Are you looking to integrate a powerful and customizable chat view into your Flutter app? Look no further! With the ChatView Flutter package, you can effortlessly add a feature-rich chat interface to your application. Whether you need a one-on-one chat, a group chat, or advanced messaging features like reactions and link previews, ChatView has got you covered. In this blog post, we will explore the capabilities of ChatView and guide you through its installation and usage.
Features of ChatView
ChatView comes with a wide range of features that enable you to create a seamless and engaging chat experience for your users. Here are some of the key features:
- One-on-one and group chat support: Easily implement both one-on-one and group chats in your app.
- Message reactions: Allow users to react to messages with emojis, adding an extra layer of expression to their conversations.
- Reply messages: Enable users to reply to specific messages, enhancing the context and clarity of conversations.
- Link preview: Automatically generate preview information for shared URLs, giving users a glimpse of the linked content.
- Configurable overall view: Customize the appearance and behavior of the chat view to align with your app's design and requirements.
Installation
To get started with ChatView, follow these simple steps:
- Add the ChatView dependency to your
pubspec.yaml
file:
dependencies: chatview2: <latest-version>
- Retrieve the latest version of the package from pub.dev or the "Installing" tab on the package's page.
- Import the package into your Flutter project:
import 'package:chatview2/chatview2.dart';
Usage
Once you have installed the package and imported it into your project, you can begin using ChatView. Here's a basic example of how to integrate ChatView into your app:
- Set up a
ChatController
:
final chatController = ChatController( initialMessageList: messageList, scrollController: ScrollController(), chatUsers: [ChatUser(id: '2', name: 'Simform')], );
- Add the
ChatView
widget to your UI:
ChatView( currentUser: ChatUser(id: '1', name: 'Flutter'), chatController: chatController, onSendTap: onSendTap, chatViewState: ChatViewState.hasMessages, )
- Define a
messageList
with initial messages:
List<Message> messageList = [ Message( id: '1', message: "Hi", createdAt: createdAt, sendBy: userId, ), Message( id: '2', message: "Hello", createdAt: createdAt, sendBy: userId, ), ];
- Implement the
onSendTap
callback to handle sending messages:
void onSendTap( String message, ReplyMessage replyMessage, Message messageType) { final message = Message( id: '3', message: "How are you", createdAt: DateTime.now(), sendBy: currentUser.id, replyMessage: replyMessage, messageType: messageType, ); chatController.addMessage(message); }
This is just a basic example to help you get started. ChatView provides many customization options to tailor the chat view to your specific needs. You can configure message types, platform-specific settings, chat bubble styles, swipe gestures, message reactions, link previews, and more.
Documentation and Examples
For a more comprehensive understanding of ChatView and its various configuration options.
Messages types compability
Message Types Android iOS MacOS Web Linux Windows
Text messages ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Image messages ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Voice messages ✔️ ✔️ ❌ ❌ ❌ ❌
Custom messages ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Platform specific configuration
For image Picker
iOS
- Add the following keys to your Info.plist file, located in
<project root>/ios/Runner/Info.plist
:
<key>NSCameraUsageDescription</key> <string>Used to demonstrate image picker plugin</string> <key>NSMicrophoneUsageDescription</key> <string>Used to capture audio for image picker plugin</string> <key>NSPhotoLibraryUsageDescription</key> <string>Used to demonstrate image picker plugin</string>
For voice messages
iOS
- Add this two rows in
ios/Runner/Info.plist
<key>NSMicrophoneUsageDescription</key> <string>This app requires Mic permission.</string>
- This plugin requires ios 10.0 or higher. So add this line in
Podfile
platform :ios, '10.0'
Android
- Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.
minSdkVersion 21
- Add RECORD_AUDIO permission in
AndroidManifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
Some more optional parameters
- Enable and disable specific features with
FeatureActiveConfig
.
ChatView( ... featureActiveConfig: FeatureActiveConfig( enableSwipeToReply: true, enableSwipeToSeeTime: false, ), ... )
- Adding an appbar with
ChatViewAppBar
.
ChatView( ... appBar: ChatViewAppBar( profilePicture: profileImage, chatTitle: "Simform", userStatus: "online", actions: [ Icon(Icons.more_vert), ], ), ... )
- Adding a message list configuration with
ChatBackgroundConfiguration
class.
ChatView( ... chatBackgroundConfig: ChatBackgroundConfiguration( backgroundColor: Colors.white, backgroundImage: backgroundImage, ), ... )
- Adding a send message configuration with
SendMessageConfiguration
class.
ChatView( ... sendMessageConfig: SendMessageConfiguration( replyMessageColor: Colors.grey, replyDialogColor:Colors.blue, replyTitleColor: Colors.black, closeIconColor: Colors.black, ), ... )
- Adding a chat bubble configuration with
ChatBubbleConfiguration
class.
ChatView( ... chatBubbleConfig: ChatBubbleConfiguration( onDoubleTap: (){ // Your code goes here }, outgoingChatBubbleConfig: ChatBubble( // Sender's message chat bubble color: Colors.blue, borderRadius: const BorderRadius.only( topRight: Radius.circular(12), topLeft: Radius.circular(12), bottomLeft: Radius.circular(12), ), ), inComingChatBubbleConfig: ChatBubble( // Receiver's message chat bubble color: Colors.grey.shade200, borderRadius: const BorderRadius.only( topLeft: Radius.circular(12), topRight: Radius.circular(12), bottomRight: Radius.circular(12), ), ), ) ... )
- Adding swipe to reply configuration with
SwipeToReplyConfiguration
class.
ChatView( ... swipeToReplyConfig: SwipeToReplyConfiguration( onLeftSwipe: (message, sendBy){ // Your code goes here }, onRightSwipe: (message, sendBy){ // Your code goes here }, ), ... )
- Adding messages configuration with
MessageConfiguration
class.
ChatView( ... messageConfig: MessageConfiguration( messageReactionConfig: MessageReactionConfiguration(), // Emoji reaction configuration for single message imageMessageConfig: ImageMessageConfiguration( onTap: (){ // Your code goes here }, shareIconConfig: ShareIconConfiguration( onPressed: (){ // Your code goes here }, ), ), ), ... )
- Adding reaction pop-up configuration with
ReactionPopupConfiguration
class.
ChatView( ... reactionPopupConfig: ReactionPopupConfiguration( backgroundColor: Colors.white, userReactionCallback: (message, emoji){ // Your code goes here } padding: EdgeInsets.all(12), shadow: BoxShadow( color: Colors.black54, blurRadius: 20, ), ), ... )
- Adding reply pop-up configuration with
ReplyPopupConfiguration
class.
ChatView( ... replyPopupConfig: ReplyPopupConfiguration( backgroundColor: Colors.white, onUnsendTap:(message){ // message is 'Message' class instance // Your code goes here }, onReplyTap:(message){ // message is 'Message' class instance // Your code goes here }, onReportTap:(){ // Your code goes here }, onMoreTap:(){ // Your code goes here }, ), ... )
- Adding replied message configuration with
RepliedMessageConfiguration
class.
ChatView( ... repliedMessageConfig: RepliedMessageConfiguration( backgroundColor: Colors.blue, verticalBarColor: Colors.black, repliedMsgAutoScrollConfig: RepliedMsgAutoScrollConfig(), ), ... )
- For customizing typing indicators use
typeIndicatorConfig
withTypeIndicatorConfig
.
ChatView( ... typeIndicatorConfig: TypeIndicatorConfiguration( flashingCircleBrightColor: Colors.grey, flashingCircleDarkColor: Colors.black, ), ... )
- For showing hiding typeIndicatorwidget use
ChatController.setTypingIndicaor
, for more info seeChatController
.
/// use it with your [ChatController] instance. _chatContoller.setTypingIndicator = true; // for showing indicator _chatContoller.setTypingIndicator = false; // for hiding indicator
- Adding linkpreview configuration with
LinkPreviewConfiguration
class.
ChatView( ... chatBubbleConfig: ChatBubbleConfiguration( linkPreviewConfig: LinkPreviewConfiguration( linkStyle: const TextStyle( color: Colors.white, decoration: TextDecoration.underline, ), backgroundColor: Colors.grey, bodyStyle: const TextStyle( color: Colors.grey.shade200, fontSize:16, ), titleStyle: const TextStyle( color: Colors.black, fontSize:20, ), ), ) ... )
- Adding pagination.
ChatView( ... isLastPage: false, featureActiveConfig: FeatureActiveConfig( enablePagination: true, ), loadMoreData: chatController.loadMoreData, ... )
- Add image picker icon configuration.
ChatView( ... sendMessageConfig: SendMessageConfiguration( imagePickerIconsConfig: ImagePickerIconsConfiguration( cameraIconColor: Colors.black, galleryIconColor: Colors.black, ) ) ... )
- Add
ChatViewState
customisations.
ChatView( ... chatViewStateConfig: ChatViewStateConfiguration( loadingWidgetConfig: ChatViewStateWidgetConfiguration( loadingIndicatorColor: Colors.pink, ), onReloadButtonTap: () {}, ), ... )
- Setting auto scroll and highlight config with
RepliedMsgAutoScrollConfig
class.
ChatView( ... repliedMsgAutoScrollConfig: RepliedMsgAutoScrollConfig( enableHighlightRepliedMsg: true, highlightColor: Colors.grey, highlightScale: 1.1, ) ... )
- Callback when a user starts/stops typing in
TextFieldConfiguration
ChatView( ... sendMessageConfig: SendMessageConfiguration( textFieldConfig: TextFieldConfiguration( onMessageTyping: (status) { // send composing/composed status to other client // your code goes here }, /// After typing stopped, the threshold time after which the composing /// status to be changed to [TypeWriterStatus.typed]. /// Default is 1 second. compositionThresholdTime: const Duration(seconds: 1), ), ... ) )
- Passing customReceipts builder or handling stuffs related receipts see
ReceiptsWidgetConfig
in outgoingChatBubbleConfig.
ChatView( ... featureActiveConfig: const FeatureActiveConfig( /// Controls the visibility of message seen ago receipts default is true lastSeenAgoBuilderVisibility: false, /// Controls the visibility of the message [receiptsBuilder] receiptsBuilderVisibility: false), ChatBubbleConfiguration( inComingChatBubbleConfig: ChatBubble( onMessageRead: (message) { /// send your message reciepts to the other client debugPrint('Message Read'); }, ), outgoingChatBubbleConfig: ChatBubble( receiptsWidgetConfig: ReceiptsWidgetConfig( /// custom receipts builder receiptsBuilder: _customReceiptsBuilder, /// whether to display receipts in all /// message or just at the last one just like instagram showReceiptsIn: ShowReceiptsIn.lastMessage ), ), ), ... )
How to use
Check out blog for better understanding and basic implementation.
Also, for whole example, check out the example app in the example directory or the 'Example' tab on pub.dartlang.org for a more complete example.