Skip to content

Commit c24090e

Browse files
🔨 Refactor code 📝 Update README.md and CHANGELOG.md.
1 parent 8a5cd31 commit c24090e

14 files changed

+187
-117
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [1.1.0]
2+
3+
* **Feat**: [37](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/37) Ability to
4+
enable or disable specific features.
5+
* **Feat**: [34](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/34) Ability to
6+
add voice message.
7+
* **Breaking**: Remove `onEmojiTap` from `ReactionPopupConfiguration`, it can be handled internally.
8+
* **Breaking**: Remove `horizontalDragToShowMessageTime` from `ChatBackgroundConfiguration` and
9+
add `enableSwipeToSeeTime` parameter with same feature in `FeatureActiveConfig`.
10+
* **Breaking**: Remove `showReceiverProfileCircle` and add `enableOtherUserProfileAvatar` parameter
11+
with same feature in `FeatureActiveConfig`.
12+
113
## [1.0.1]
214

315
* **Fix**: [32](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/32) Fix issue of

README.md

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void onSendTap(String message, ReplyMessage replyMessage){
7272
message: "How are you",
7373
createdAt: DateTime.now(),
7474
sendBy: currentUser.id,
75+
replyMessage: replyMessage,
7576
);
7677
chatController.addMessage(message);
7778
}
@@ -86,11 +87,28 @@ void onSendTap(String message, ReplyMessage replyMessage){
8687
createdAt: DateTime.now(),
8788
sendBy: currentUser.id,
8889
messageType: MessageType.image,
90+
replyMessage: replyMessage,
8991
);
9092
chatController.addMessage(message);
9193
}
9294
```
9395

96+
7. Sending voice message.
97+
```dart
98+
void onRecordingComplete(String audioPath, ReplyMessage replyMessage){
99+
final message = Message(
100+
id: '3',
101+
message: audioPath,
102+
createdAt: DateTime.now(),
103+
sendBy: currentUser.id,
104+
messageType: MessageType.voice,
105+
replyMessage: replyMessage,
106+
);
107+
chatController.addMessage(message);
108+
}
109+
```
110+
Note: This function needs to pass in `onRecordingComplete` parameter in `ChatView` class.
111+
94112
## Platform specific configuration for image picker
95113

96114
### iOS
@@ -103,9 +121,22 @@ Add the following keys to your _Info.plist_ file, located in `<project root>/ios
103121

104122
## Some more optional parameters
105123

106-
1. Adding an appbar with `ChatViewAppBar`.
124+
1. Enable and disable specific features with `FeatureActiveConfig`.
107125
```dart
108126
ChatView(
127+
...
128+
featureActiveConfig: FeatureActiveConfig(
129+
enableSwipeToReply: true,
130+
enableSwipeToSeeTime: false,
131+
),
132+
...
133+
)
134+
```
135+
136+
2. Adding an appbar with `ChatViewAppBar`.
137+
```dart
138+
ChatView(
139+
...
109140
appBar: ChatViewAppBar(
110141
profilePicture: profileImage,
111142
chatTitle: "Simform",
@@ -114,10 +145,11 @@ ChatView(
114145
Icon(Icons.more_vert),
115146
],
116147
),
148+
...
117149
)
118150
```
119151

120-
2. Adding a message list configuration with `ChatBackgroundConfiguration` class.
152+
3. Adding a message list configuration with `ChatBackgroundConfiguration` class.
121153
```dart
122154
ChatView(
123155
...
@@ -129,7 +161,7 @@ ChatView(
129161
)
130162
```
131163

132-
3. Adding a send message configuration with `SendMessageConfiguration` class.
164+
4. Adding a send message configuration with `SendMessageConfiguration` class.
133165
```dart
134166
ChatView(
135167
...
@@ -138,23 +170,11 @@ ChatView(
138170
replyDialogColor:Colors.blue,
139171
replyTitleColor: Colors.black,
140172
closeIconColor: Colors.black,
141-
horizontalDragToShowMessageTime: true, // to show message created time
142173
),
143174
...
144175
)
145176
```
146177

147-
4. Adding a receiver's profile image.
148-
```dart
149-
ChatView(
150-
...
151-
showReceiverProfileCircle: true,
152-
profileCircleConfig: ProfileCircleConfiguration(profileImageUrl: profileImage),
153-
/// Add profileImage url of recevier
154-
...
155-
)
156-
```
157-
158178
5. Adding a chat bubble configuration with `ChatBubbleConfiguration` class.
159179
```dart
160180
ChatView(
@@ -227,9 +247,11 @@ ChatView(
227247
...
228248
reactionPopupConfig: ReactionPopupConfiguration(
229249
backgroundColor: Colors.white,
230-
onEmojiTap: (emoji, messageId){
231-
chatController.setReaction(emoji,messageId);
232-
},
250+
padding: EdgeInsets.all(12),
251+
shadow: BoxShadow(
252+
color: Colors.black54,
253+
blurRadius: 20,
254+
),
233255
),
234256
...
235257
)
@@ -314,7 +336,9 @@ ChatView(
314336
ChatView(
315337
...
316338
isLastPage: false,
317-
enablePagination: true,
339+
featureActiveConfig: FeatureActiveConfig(
340+
enablePagination: true,
341+
),
318342
loadMoreData: chatController.loadMoreData,
319343
...
320344
)
@@ -363,6 +387,19 @@ ChatView(
363387
...
364388
)
365389
```
390+
391+
17. Setting auto scroll and highlight config with `RepliedMsgAutoScrollConfig` class.
392+
```dart
393+
ChatView(
394+
...
395+
repliedMsgAutoScrollConfig: RepliedMsgAutoScrollConfig(
396+
enableHighlightRepliedMsg: true,
397+
highlightColor: Colors.grey,
398+
highlightScale: 1.1,
399+
)
400+
...
401+
)
402+
```
366403
## How to use
367404

368405
Check out the **example** app in the [example](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/tree/main/example) directory or the 'Example' tab on pub.dartlang.org for a more complete example.

example/lib/data.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Data {
3333
message: "That's fine",
3434
createdAt: DateTime.now(),
3535
sendBy: '2',
36-
reaction: Reaction(reactions: ['❤️'], reactedUserIds: ['1']),
36+
reaction: Reaction(reactions: ['\u{2764}'], reactedUserIds: ['1']),
3737
),
3838
Message(
3939
id: '6',
@@ -53,7 +53,7 @@ class Data {
5353
createdAt: DateTime.now(),
5454
sendBy: '2',
5555
reaction: Reaction(
56-
reactions: ['❤️', '👍', '👍'],
56+
reactions: ['\u{2764}', '\u{1F44D}', '\u{1F44D}'],
5757
reactedUserIds: ['2', '3', '4'],
5858
),
5959
replyMessage: const ReplyMessage(
@@ -70,9 +70,9 @@ class Data {
7070
sendBy: '1',
7171
reaction: Reaction(
7272
reactions: [
73-
'❤️',
74-
'❤️',
75-
'❤️',
73+
'\u{2764}',
74+
'\u{2764}',
75+
'\u{2764}',
7676
],
7777
reactedUserIds: ['2', '3', '4'],
7878
),
@@ -83,7 +83,7 @@ class Data {
8383
createdAt: DateTime.now(),
8484
sendBy: '1',
8585
reaction: Reaction(
86-
reactions: ['❤️', '❤️', '❤️', '❤️'],
86+
reactions: ['\u{2764}', '\u{2764}', '\u{2764}', '\u{2764}'],
8787
reactedUserIds: ['2', '4', '3', '1'],
8888
),
8989
),
@@ -93,7 +93,7 @@ class Data {
9393
createdAt: DateTime.now(),
9494
messageType: MessageType.image,
9595
sendBy: '1',
96-
reaction: Reaction(reactions: ['❤️'], reactedUserIds: ['2']),
96+
reaction: Reaction(reactions: ['\u{2764}'], reactedUserIds: ['2']),
9797
),
9898
Message(
9999
id: '12',

example/lib/main.dart

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,30 @@ class _ChatScreenState extends State<ChatScreen> {
124124
backgroundColor: theme.backgroundColor,
125125
),
126126
sendMessageConfig: SendMessageConfiguration(
127-
imagePickerIconsConfig: ImagePickerIconsConfiguration(
128-
cameraIconColor: theme.cameraIconColor,
129-
galleryIconColor: theme.galleryIconColor,
130-
),
131-
replyMessageColor: theme.replyMessageColor,
132-
defaultSendButtonColor: theme.sendButtonColor,
133-
replyDialogColor: theme.replyDialogColor,
134-
replyTitleColor: theme.replyTitleColor,
135-
textFieldBackgroundColor: theme.textFieldBackgroundColor,
136-
closeIconColor: theme.closeIconColor,
137-
textFieldConfig: TextFieldConfiguration(
138-
textStyle: TextStyle(color: theme.textFieldTextColor),
127+
imagePickerIconsConfig: ImagePickerIconsConfiguration(
128+
cameraIconColor: theme.cameraIconColor,
129+
galleryIconColor: theme.galleryIconColor,
130+
),
131+
replyMessageColor: theme.replyMessageColor,
132+
defaultSendButtonColor: theme.sendButtonColor,
133+
replyDialogColor: theme.replyDialogColor,
134+
replyTitleColor: theme.replyTitleColor,
135+
textFieldBackgroundColor: theme.textFieldBackgroundColor,
136+
closeIconColor: theme.closeIconColor,
137+
textFieldConfig: TextFieldConfiguration(
138+
textStyle: TextStyle(color: theme.textFieldTextColor),
139+
),
140+
micIconColor: theme.replyMicIconColor,
141+
voiceRecordingConfiguration: VoiceRecordingConfiguration(
142+
backgroundColor: theme.waveformBackgroundColor,
143+
recorderIconColor: theme.recordIconColor,
144+
waveStyle: WaveStyle(
145+
showMiddleLine: false,
146+
waveColor: theme.waveColor ?? Colors.white,
147+
extendWaveform: true,
139148
),
140-
micIconColor: theme.replyMicIconColor,
141-
voiceRecordingConfiguration: VoiceRecordingConfiguration(
142-
backgroundColor: theme.waveformBackgroundColor,
143-
recorderIconColor: theme.recordIconColor,
144-
waveStyle: WaveStyle(
145-
showMiddleLine: false,
146-
waveColor: theme.waveColor ?? Colors.white,
147-
extendWaveform: true,
148-
),
149-
)),
149+
),
150+
),
150151
chatBubbleConfig: ChatBubbleConfiguration(
151152
outgoingChatBubbleConfig: ChatBubble(
152153
linkPreviewConfig: LinkPreviewConfiguration(
@@ -183,11 +184,6 @@ class _ChatScreenState extends State<ChatScreen> {
183184
blurRadius: 20,
184185
),
185186
backgroundColor: theme.reactionPopupColor,
186-
onEmojiTap: (emoji, messageId) => _chatController.setReaction(
187-
emoji: emoji,
188-
messageId: messageId,
189-
userId: currentUser.id,
190-
),
191187
),
192188
messageConfig: MessageConfiguration(
193189
messageReactionConfig: MessageReactionConfiguration(

lib/src/models/reaction_popup_configuration.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
*/
2222
import 'package:flutter/material.dart';
2323

24-
import '../values/typedefs.dart';
25-
2624
class ReactionPopupConfiguration {
2725
final Color? backgroundColor;
2826
final BoxShadow? shadow;
@@ -32,7 +30,6 @@ class ReactionPopupConfiguration {
3230
final EdgeInsetsGeometry? padding;
3331
final EmojiConfiguration? emojiConfig;
3432
final bool showGlassMorphismEffect;
35-
final StringsCallBack? onEmojiTap;
3633
final GlassMorphismConfiguration? glassMorphismConfig;
3734

3835
ReactionPopupConfiguration({
@@ -43,7 +40,6 @@ class ReactionPopupConfiguration {
4340
this.maxWidth,
4441
this.margin,
4542
this.padding,
46-
this.onEmojiTap,
4743
this.emojiConfig,
4844
this.glassMorphismConfig,
4945
});

lib/src/widgets/chat_bubble_widget.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class ChatBubbleWidget extends StatefulWidget {
3838
required this.showReceiverProfileCircle,
3939
required this.slideAnimation,
4040
required this.onSwipe,
41-
required this.currentUser,
4241
this.profileCircleConfig,
4342
this.chatBubbleConfig,
4443
this.repliedMessageConfig,
@@ -62,7 +61,6 @@ class ChatBubbleWidget extends StatefulWidget {
6261
final Animation<Offset>? slideAnimation;
6362
final MessageConfiguration? messageConfig;
6463
final MessageCallBack onSwipe;
65-
final ChatUser currentUser;
6664
final Function(String)? onReplyTap;
6765
final bool shouldHighlight;
6866

@@ -73,10 +71,11 @@ class ChatBubbleWidget extends StatefulWidget {
7371
class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
7472
String get replyMessage => widget.message.replyMessage.message;
7573

76-
bool get isMessageBySender => widget.message.sendBy == widget.currentUser.id;
74+
bool get isMessageBySender => widget.message.sendBy == currentUser?.id;
7775

7876
FeatureActiveConfig? featureActiveConfig;
7977
ChatController? chatController;
78+
ChatUser? currentUser;
8079
int? maxDuration;
8180

8281
@override
@@ -85,6 +84,7 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
8584
if (provide != null) {
8685
featureActiveConfig = provide!.featureActiveConfig;
8786
chatController = provide!.chatController;
87+
currentUser = provide!.currentUser;
8888
}
8989
}
9090

@@ -193,7 +193,7 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
193193
? widget.profileCircleConfig?.bottomPadding ?? 15
194194
: widget.profileCircleConfig?.bottomPadding ?? 2,
195195
profileCirclePadding: widget.profileCircleConfig?.padding,
196-
imageUrl: widget.currentUser.profilePhoto,
196+
imageUrl: currentUser?.profilePhoto,
197197
circleRadius: widget.profileCircleConfig?.circleRadius,
198198
),
199199
],
@@ -224,7 +224,6 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
224224
: ReplyMessageWidget(
225225
message: widget.message,
226226
repliedMessageConfig: widget.repliedMessageConfig,
227-
currentUser: widget.currentUser,
228227
onTap: () => widget.onReplyTap
229228
?.call(widget.message.replyMessage.messageId),
230229
),
@@ -245,11 +244,13 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
245244
widget.chatBubbleConfig?.longPressAnimationDuration,
246245
onDoubleTap: featureActiveConfig?.enableDoubleTapToLike ?? false
247246
? widget.chatBubbleConfig?.onDoubleTap ??
248-
(message) => chatController?.setReaction(
249-
emoji: heart,
250-
messageId: message.id,
251-
userId: widget.currentUser.id,
252-
)
247+
(message) => currentUser != null
248+
? chatController?.setReaction(
249+
emoji: heart,
250+
messageId: message.id,
251+
userId: currentUser!.id,
252+
)
253+
: null
253254
: null,
254255
shouldHighlight: widget.shouldHighlight,
255256
highlightColor: widget.repliedMessageConfig

0 commit comments

Comments
 (0)