حزمة Flutter تسمح لك بدمج طريقة عرض الدردشة مع خيارات التخصيص العالية مثل الدردشة الفردية والدردشة الجماعية وتفاعلات الرسائل والرد على الرسائل ومعاينة الارتباط وتكوينات العرض العام.
للحصول على عرض توضيحي على الويب، تفضل بزيارة مثال عرض الدردشة.
تمت إعادة تسمية الحقل sendBy
إلى sentBy
في فئة Message
.
تمت إعادة تسمية حقل chatUsers
إلى otherUsers
في فئة ChatController
.
تم نقل حقل currentUser
من عنصر واجهة ChatView
إلى فئة ChatController
تم تحديث قيمة id
في طريقة copyWith
Message
للحصول على القيمة الصحيحة.
تمت إزالة حقل showTypingIndicator
من ChatView
واستبداله بـ ChatController.showTypingIndicator
.
قبل:
ChatView (
showTypingIndicator : false ,
),
بعد:
/// use it with your [ChatController] instance.
_chatContoller.setTypingIndicator = true ; // for showing indicator
_chatContoller.setTypingIndicator = false ; // for hiding indicator
تم تحديث أساليب ChatUser
و Message
و ReplyMessage
Data Model fromJson
و toJson
:
ChatUser.fromJson
:قبل:
ChatUser . fromJson (
{
...
'imageType' : ImageType .asset,
...
},
),
بعد:
ChatUser . fromJson (
{
...
'imageType' : 'asset' ,
...
},
),
ChatUser.toJson
:قبل:
{
...
imageType : ImageType .asset,
...
}
بعد:
{
...
imageType : asset,
...
}
Message.fromJson
.fromJson :قبل:
Message . fromJson (
{
...
'createdAt' : DateTime . now (),
'message_type' : MessageType .text,
'voice_message_duration' : Duration (seconds : 5 ),
...
}
)
بعد:
Message . fromJson (
{
...
'createdAt' : '2024-06-13T17:32:19.586412' ,
'message_type' : 'text' ,
'voice_message_duration' : '5000000' ,
...
}
)
Message.toJson
.toJson :قبل:
{
...
createdAt : 2024 - 06 - 13 17 : 23 : 19.454789 ,
message_type : MessageType .text,
voice_message_duration : 0 : 00 : 05.000000 ,
...
}
بعد:
{
...
createdAt : 2024 - 06 - 13T17 : 32 : 19.586412 ,
message_type : text,
voice_message_duration : 5000000 ,
...
}
ReplyMessage.fromJson
:قبل:
ReplyMessage . fromJson (
{
...
'message_type' : MessageType .text,
'voiceMessageDuration' : Duration (seconds : 5 ),
...
}
)
بعد:
ReplyMessage . fromJson (
{
...
'message_type' : 'text' ,
'voiceMessageDuration' : '5000000' ,
...
}
)
في ReplyMessage.toJson
:
قبل:
{
...
message_type : MessageType .text,
voiceMessageDuration : 0 : 00 : 05.000000 ,
...
}
بعد:
{
...
message_type : text,
voiceMessageDuration : 5000000 ,
...
}
pubspec.yaml
dependencies :
chatview : < latest - version >
احصل على أحدث إصدار في علامة التبويب "التثبيت" على pub.dev
import 'package:chatview/chatview.dart' ;
final chatController = ChatController (
initialMessageList : messageList,
scrollController : ScrollController (),
currentUser : ChatUser (id : '1' , name : 'Flutter' ),
otherUsers : [ ChatUser (id : '2' , name : 'Simform' )],
);
ChatView
. ChatView (
chatController : chatController,
onSendTap : onSendTap,
chatViewState : ChatViewState .hasMessages, // Add this state once data is available.
)
Message
. List < Message > messageList = [
Message (
id : '1' ,
message : "Hi" ,
createdAt : createdAt,
sentBy : userId,
),
Message (
id : '2' ,
message : "Hello" ,
createdAt : createdAt,
sentBy : userId,
),
];
onSendTap
. void onSendTap ( String message, ReplyMessage replyMessage, MessageType messageType){
final message = Message (
id : '3' ,
message : "How are you" ,
createdAt : DateTime . now (),
sentBy : currentUser.id,
replyMessage : replyMessage,
messageType : messageType,
);
chatController. addMessage (message);
}
ملاحظة: يمكنك تقييم نوع الرسالة من معلمة messageType
، بناءً على أنه يمكنك تنفيذ العمليات.
أنواع الرسائل | أندرويد | دائرة الرقابة الداخلية | ماك | ويب | لينكس | ويندوز |
---|---|---|---|---|---|---|
رسائل نصية | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
رسائل الصور | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
رسائل صوتية | ✔️ | ✔️ | ||||
رسائل مخصصة | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
<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>
ios/Runner/Info.plist
<key>NSMicrophoneUsageDescription</key>
<string>This app requires Mic permission.</string>
Podfile
platform :ios, '10.0'
minSdkVersion 21
AndroidManifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
FeatureActiveConfig
. ChatView (
...
featureActiveConfig : FeatureActiveConfig (
enableSwipeToReply : true ,
enableSwipeToSeeTime : false ,
),
...
)
ChatViewAppBar
. ChatView (
...
appBar : ChatViewAppBar (
profilePicture : profileImage,
chatTitle : "Simform" ,
userStatus : "online" ,
actions : [
Icon ( Icons .more_vert),
],
),
...
)
ChatBackgroundConfiguration
. ChatView (
...
chatBackgroundConfig : ChatBackgroundConfiguration (
backgroundColor : Colors .white,
backgroundImage : backgroundImage,
),
...
)
SendMessageConfiguration
. ChatView (
...
sendMessageConfig : SendMessageConfiguration (
replyMessageColor : Colors .grey,
replyDialogColor : Colors .blue,
replyTitleColor : Colors .black,
closeIconColor : Colors .black,
),
...
)
ChatBubbleConfiguration
. 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 ),
),
),
)
...
)
SwipeToReplyConfiguration
. ChatView (
...
swipeToReplyConfig : SwipeToReplyConfiguration (
onLeftSwipe : (message, sentBy){
// Your code goes here
},
onRightSwipe : (message, sentBy){
// Your code goes here
},
),
...
)
MessageConfiguration
. 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
},
),
),
),
...
)
ReactionPopupConfiguration
. ChatView (
...
reactionPopupConfig : ReactionPopupConfiguration (
backgroundColor : Colors .white,
userReactionCallback : (message, emoji){
// Your code goes here
}
padding : EdgeInsets . all ( 12 ),
shadow : BoxShadow (
color : Colors .black54,
blurRadius : 20 ,
),
),
...
)
ReplyPopupConfiguration
. 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
},
),
...
)
RepliedMessageConfiguration
. ChatView (
...
repliedMessageConfig : RepliedMessageConfiguration (
backgroundColor : Colors .blue,
verticalBarColor : Colors .black,
repliedMsgAutoScrollConfig : RepliedMsgAutoScrollConfig (),
),
...
)
typeIndicatorConfig
مع TypeIndicatorConfig
. ChatView (
...
typeIndicatorConfig : TypeIndicatorConfiguration (
flashingCircleBrightColor : Colors .grey,
flashingCircleDarkColor : Colors .black,
),
...
)
ChatController.setTypingIndicaor
، لمزيد من المعلومات، راجع ChatController
. /// use it with your [ChatController] instance.
_chatContoller.setTypingIndicator = true ; // for showing indicator
_chatContoller.setTypingIndicator = false ; // for hiding indicator
LinkPreviewConfiguration
. 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 ,
),
),
)
...
)
ChatView (
...
isLastPage : false ,
featureActiveConfig : FeatureActiveConfig (
enablePagination : true ,
),
loadMoreData : chatController.loadMoreData,
...
)
ChatView (
...
sendMessageConfig : SendMessageConfiguration (
enableCameraImagePicker : false ,
enableGalleryImagePicker : true ,
imagePickerIconsConfig : ImagePickerIconsConfiguration (
cameraIconColor : Colors .black,
galleryIconColor : Colors .black,
)
)
...
)
ChatViewState
. ChatView (
...
chatViewStateConfig : ChatViewStateConfiguration (
loadingWidgetConfig : ChatViewStateWidgetConfiguration (
loadingIndicatorColor : Colors .pink,
),
onReloadButtonTap : () {},
),
...
)
RepliedMsgAutoScrollConfig
. ChatView (
...
repliedMsgAutoScrollConfig : RepliedMsgAutoScrollConfig (
enableHighlightRepliedMsg : true ,
highlightColor : Colors .grey,
highlightScale : 1.1 ,
)
...
)
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 ),
),
...
)
)
ReceiptsWidgetConfig
في 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
),
),
),
...
)
enableOtherUserName
لإخفاء اسم المستخدم في الدردشة. ChatView (
...
featureActiveConfig : const FeatureActiveConfig (
enableOtherUserName : false ,
),
...
)
onMoreTap
و onReportTap
. ChatView (
...
replyPopupConfig : ReplyPopupConfiguration (
onReportTap : ( Message message) {
debugPrint ( 'Message: $ message ' );
},
onMoreTap : ( Message message, bool sentByCurrentUser) {
debugPrint ( 'Message : $ message ' );
},
),
...
)
emojiPickerSheetConfig
لتكوين ورقة منتقي الرموز التعبيرية. ChatView (
...
emojiPickerSheetConfig : Config (
emojiViewConfig : EmojiViewConfig (
columns : 7 ,
emojiSizeMax : 32 ,
recentsLimit : 28 ,
backgroundColor : Colors .white,
),
categoryViewConfig : const CategoryViewConfig (
initCategory : Category . RECENT ,
recentTabBehavior : RecentTabBehavior . NONE ,
),
...
)
VoiceRecordingConfiguration
في sendMessageConfig. ChatView (
...
sendMessageConfig : SendMessageConfiguration (
voiceRecordingConfiguration : VoiceRecordingConfiguration (
iosEncoder : IosEncoder .kAudioFormatMPEG4AAC,
androidOutputFormat : AndroidOutputFormat .mpeg4,
androidEncoder : AndroidEncoder .aac,
bitRate : 128000 ,
sampleRate : 44100 ,
waveStyle : WaveStyle (
showMiddleLine : false ,
waveColor : theme.waveColor ?? Colors .white,
extendWaveform : true ,
),
),
...
)
)
enabled
لتمكين/تعطيل حقل نص الدردشة. ChatView (
...
sendMessageConfig : SendMessageConfiguration (
...
textFieldConfig : TextFieldConfig (
enabled : true // [false] to disable text field.
),
...
),
...
)
isProfilePhotoInBase64
التي تحدد ما إذا كانت الصورة المقدمة عبارة عن بيانات url أو بيانات base64. final chatController = ChatController (
...
chatUsers : [
ChatUser (
id : '1' ,
name : 'Simform' ,
isProfilePhotoInBase64 : false ,
profilePhoto : 'ImageNetworkUrl' ,
),
],
...
);
ChatView (
...
profileCircleConfig : const ProfileCircleConfiguration (
isProfilePhotoInBase64 : false ,
profileImageUrl : 'ImageNetworkUrl' ,
),
...
)
chatSeparatorDatePattern
في DefaultGroupSeparatorConfiguration
لفصل الدردشات بالنمط المقدم. ChatView (
...
chatBackgroundConfig : ChatBackgroundConfiguration (
...
defaultGroupSeparatorConfig : DefaultGroupSeparatorConfiguration (
chatSeparatorDatePattern : 'MMM dd, yyyy'
),
...
),
...
)
cancelRecordConfiguration
لتوفير تكوين لإلغاء رسالة التسجيل الصوتي. ChatView (
...
sendMessageConfig : SendMessageConfiguration (
...
cancelRecordConfiguration : CancelRecordConfiguration (
icon : const Icon (
Icons .cancel_outlined,
),
onCancel : () {
debugPrint ( 'Voice recording cancelled' );
},
iconColor : Colors .black,
),
...
),
...
)
reactedUserCallback
. ChatView (
...
messageConfig : MessageConfiguration (
...
messageReactionConfig : MessageReactionConfiguration (
reactionsBottomSheetConfig : ReactionsBottomSheetConfiguration (
reactedUserCallback : (reactedUser, reaction) {
debugPrint (reaction);
},
),
),
...
),
...
),
customMessageReplyViewBuilder
لتخصيص عرض رسالة الرد لنوع الرسالة المخصص. ChatView (
...
messageConfig : MessageConfiguration (
customMessageBuilder : ( ReplyMessage state) {
return Text (
state.message,
maxLines : 1 ,
overflow : TextOverflow .ellipsis,
style : const TextStyle (
fontSize : 12 ,
color : Colors .black,
),
);
},
),
...
)
defaultAvatarImage
، ومنشئ الأخطاء للأصول وصورة ملف تعريف الشبكة assetImageErrorBuilder
networkImageErrorBuilder
، وEnum ImageType
لتعريف الصورة كأصل أو شبكة أو بيانات base64. ChatView (
...
appBar : ChatViewAppBar (
defaultAvatarImage : defaultAvatar,
imageType : ImageType .network,
networkImageErrorBuilder : (context, url, error) {
return Center (
child : Text ( 'Error $ error ' ),
);
},
assetImageErrorBuilder : (context, error, stackTrace) {
return Center (
child : Text ( 'Error $ error ' ),
);
},
),
...
),
customMessageReplyViewBuilder
لتخصيص عرض رسالة الرد لنوع الرسالة المخصص. ChatView (
...
messageConfig : MessageConfiguration (
customMessageBuilder : ( ReplyMessage state) {
return Text (
state.message,
maxLines : 1 ,
overflow : TextOverflow .ellipsis,
style : const TextStyle (
fontSize : 12 ,
color : Colors .black,
),
);
},
),
...
)
replyMessageBuilder
لتخصيص عرض الرد. ChatView (
...
replyMessageBuilder : (context, state) {
return Container (
decoration : const BoxDecoration (
color : Colors .white,
borderRadius : BorderRadius . vertical (
top : Radius . circular ( 14 ),
),
),
margin : const EdgeInsets . only (
bottom : 17 ,
right : 0.4 ,
left : 0.4 ,
),
padding : const EdgeInsets . fromLTRB ( 10 , 10 , 10 , 30 ),
child : Container (
padding : const EdgeInsets . symmetric (
horizontal : 6 ,
),
decoration : BoxDecoration (
color : Colors .grey.shade200,
borderRadius : BorderRadius . circular ( 12 ),
),
child : Column (
mainAxisSize : MainAxisSize .min,
children : [
Row (
mainAxisAlignment : MainAxisAlignment .spaceBetween,
children : [
Expanded (
child : Text (
state.message,
maxLines : 1 ,
overflow : TextOverflow .ellipsis,
style : const TextStyle (
fontWeight : FontWeight .bold,
),
),
),
IconButton (
constraints : const BoxConstraints (),
padding : EdgeInsets .zero,
icon : const Icon (
Icons .close,
size : 16 ,
),
onPressed : () => ChatView . closeReplyMessageView (context),
),
],
),
],
),
),
);
},
...
)
_chatController. addReplySuggestions ([
SuggestionItemData (text : 'Thanks.' ),
SuggestionItemData (text : 'Thank you very much.' ),
SuggestionItemData (text : 'Great.' )
]);
_chatController. removeReplySuggestions ();
replySuggestionsConfig : ReplySuggestionsConfig (
itemConfig : SuggestionItemConfig (
decoration : BoxDecoration (),
textStyle : TextStyle (),
padding : EdgetInsets . all ( 8 ),
customItemBuilder : (index, suggestionItemData) => Container ()
),
listConfig : SuggestionListConfig (
decoration : BoxDecoration (),
padding : EdgetInsets . all ( 8 ),
itemSeparatorWidth : 8 ,
axisAlignment : SuggestionListAlignment .left
)
onTap : (item) =>
_onSendTap (item.text, const ReplyMessage (), MessageType .text),
autoDismissOnSelection : true
),
messageSorter
رد الاتصال لفرز الرسائل في ChatBackgroundConfiguration
. ChatView (
...
chatBackgroundConfig : ChatBackgroundConfiguration (
...
messageSorter : (message1, message2) {
return message1.createdAt. compareTo (message2.createdAt);
}
...
),
...
),
ScrollToBottomButtonConfig
لتغيير تكوين زر التمرير إلى الأسفل. ChatView (
...
scrollToBottomButtonConfig : ScrollToBottomButtonConfig (
),
...
),
errorBody
لعرض رسالة خطأ عندما لا يمكن تحليل الارتباط للمعاينة. ChatView (
...
linkPreviewConfig : LinkPreviewConfiguration (
errorBody : 'Error encountered while parsing the link for preview'
),
...
),
suggestionItemType
لعرض عناصر الاقتراح في أسطر متعددة وليس في شكل قابل للتمرير. ChatView (
...
replySuggestionsConfig : ReplySuggestionsConfig (
suggestionItemType : SuggestionItemsType .multiline,
),
...
),
قم بمراجعة المدونة لفهم أفضل وتنفيذ أساسي.
أيضًا، على سبيل المثال بالكامل، تحقق من التطبيق النموذجي في دليل المثال أو علامة التبويب "مثال" على pub.dartlang.org للحصول على مثال أكثر اكتمالاً.
فاتسال تانا | دهفانيت فاغاني | أوجاس ماجيثيا | أبورفا كانثرافيا | أديتيا تشافدا |
MIT License
Copyright (c) 2022 Simform Solutions
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.