Skip to content

Commit

Permalink
✨ (#65) Add callback when user react on message.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhvanit-v-simformsolutions authored and DhvanitVaghani committed Mar 6, 2023
1 parent 93a200c commit ea902b3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## (UnReleased)
## [1.2.1]

* **Fix**: [60](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/60) Fix image from
file is not loaded.
* **Fix**: [61](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/61) Fix issue of
audio message is not working.
* **Feat**: [65](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/65) Add callback
when user react on message.


## [1.2.0+1]
Expand Down
21 changes: 4 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ ChatView(
...
reactionPopupConfig: ReactionPopupConfiguration(
backgroundColor: Colors.white,
userReactionCallback: (message, emoji){
// Your code goes here
}
padding: EdgeInsets.all(12),
shadow: BoxShadow(
color: Colors.black54,
Expand Down Expand Up @@ -355,15 +358,12 @@ ChatView(
)
```

14. Get imagepath from image picker and add imagepicker icon configuration.
14. Add image picker icon configuration.
```dart
ChatView(
...
sendMessageConfig: SendMessageConfiguration(
imagePickerIconsConfig: ImagePickerIconsConfiguration(
onImageSelected: (imagePath, error){
},
cameraIconColor: Colors.black,
galleryIconColor: Colors.black,
)
Expand Down Expand Up @@ -398,19 +398,6 @@ ChatView(
...
)
```

17. Setting auto scroll and highlight config with `RepliedMsgAutoScrollConfig` class.
```dart
ChatView(
...
repliedMsgAutoScrollConfig: RepliedMsgAutoScrollConfig(
enableHighlightRepliedMsg: true,
highlightColor: Colors.grey,
highlightScale: 1.1,
)
...
)
```
## How to use

Check out [blog](https://medium.com/simform-engineering/chatview-a-cutting-edge-chat-ui-solution-7367b1f9d772) for better understanding and basic implementation.
Expand Down
22 changes: 11 additions & 11 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,17 @@ class _ChatScreenState extends State<ChatScreen> {
ReplyMessage replyMessage,
MessageType messageType,
) {
final id = int.parse(Data.messageList.last.id) + 1;
_chatController.addMessage(
Message(
id: id.toString(),
createdAt: DateTime.now(),
message: message,
sendBy: currentUser.id,
replyMessage: replyMessage,
messageType: messageType,
),
);
final id = int.parse(Data.messageList.last.id) + 1;
_chatController.addMessage(
Message(
id: id.toString(),
createdAt: DateTime.now(),
message: message,
sendBy: currentUser.id,
replyMessage: replyMessage,
messageType: messageType,
),
);
}

void _onThemeIconTap() {
Expand Down
6 changes: 6 additions & 0 deletions lib/src/models/reaction_popup_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
import 'package:flutter/material.dart';

import 'models.dart';

class ReactionPopupConfiguration {
/// Used for background color in reaction pop-up.
final Color? backgroundColor;
Expand Down Expand Up @@ -49,7 +51,11 @@ class ReactionPopupConfiguration {
/// Provides glass morphism effect configuration.
final GlassMorphismConfiguration? glassMorphismConfig;

/// Provides callback when user react on message.
final void Function(Message message, String emoji)? userReactionCallback;

ReactionPopupConfiguration({
this.userReactionCallback,
this.showGlassMorphismEffect = false,
this.backgroundColor,
this.shadow,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/chat_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
onChatBubbleLongPress: (yCoordinate, xCoordinate, message) {
if (featureActiveConfig?.enableReactionPopup ?? false) {
_reactionPopupKey.currentState?.refreshWidget(
messageId: message.id,
message: message,
xCoordinate: xCoordinate,
yCoordinate:
yCoordinate < 0 ? -(yCoordinate) - 5 : yCoordinate,
Expand Down
14 changes: 9 additions & 5 deletions lib/src/widgets/reaction_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ReactionPopupState extends State<ReactionPopup>
bool get showPopUp => widget.showPopUp;
double _yCoordinate = 0.0;
double _xCoordinate = 0.0;
String _messageId = '';
Message? _message;

ChatController? chatController;
ChatUser? currentUser;
Expand Down Expand Up @@ -155,10 +155,14 @@ class ReactionPopupState extends State<ReactionPopup>
Widget get _reactionPopupRow => EmojiRow(
onEmojiTap: (emoji) {
widget.onTap();
if (currentUser != null) {
if (currentUser != null && _message != null) {
reactionPopupConfig?.userReactionCallback?.call(
_message!,
emoji,
);
chatController?.setReaction(
emoji: emoji,
messageId: _messageId,
messageId: _message!.id,
userId: currentUser!.id,
);
}
Expand All @@ -167,12 +171,12 @@ class ReactionPopupState extends State<ReactionPopup>
);

void refreshWidget({
required String messageId,
required Message message,
required double xCoordinate,
required double yCoordinate,
}) {
setState(() {
_messageId = messageId;
_message = message;
_xCoordinate = xCoordinate;
_yCoordinate = yCoordinate;
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chatview
description: A Flutter package that allows you to integrate Chat View with highly customization options.
version: 1.2.0+1
version: 1.2.1
issue_tracker: https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues
repository: https://github.com/SimformSolutionsPvtLtd/flutter_chatview

Expand Down

0 comments on commit ea902b3

Please sign in to comment.