Skip to content

Commit c55b3a8

Browse files
committed
add secondaryCallback
1 parent c1ef794 commit c55b3a8

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

packages/flutter_chat_ui/lib/src/chat.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class Chat extends StatefulWidget {
5050
/// Callback triggered when a message is long-pressed.
5151
final OnMessageLongPressCallback? onMessageLongPress;
5252

53+
/// Callback triggered when a message is right-clicked (secondary tapped).
54+
final OnMessageSecondaryTapCallback? onMessageSecondaryTap;
55+
5356
/// Callback triggered when the attachment button in the composer is tapped.
5457
final OnAttachmentTapCallback? onAttachmentTap;
5558

@@ -79,6 +82,7 @@ class Chat extends StatefulWidget {
7982
this.onMessageSend,
8083
this.onMessageTap,
8184
this.onMessageLongPress,
85+
this.onMessageSecondaryTap,
8286
this.onAttachmentTap,
8387
this.backgroundColor,
8488
this.decoration,
@@ -150,6 +154,7 @@ class _ChatState extends State<Chat> with WidgetsBindingObserver {
150154
Provider.value(value: widget.onMessageSend),
151155
Provider.value(value: widget.onMessageTap),
152156
Provider.value(value: widget.onMessageLongPress),
157+
Provider.value(value: widget.onMessageSecondaryTap),
153158
Provider.value(value: widget.onAttachmentTap),
154159
ChangeNotifierProvider(create: (_) => ComposerHeightNotifier()),
155160
ChangeNotifierProvider(create: (_) => LoadMoreNotifier()),

packages/flutter_chat_ui/lib/src/chat_message/chat_message.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class ChatMessage extends StatelessWidget {
125125
final onMessageTap = context.read<OnMessageTapCallback?>();
126126
final onMessageDoubleTap = context.read<OnMessageDoubleTapCallback?>();
127127
final onMessageLongPress = context.read<OnMessageLongPressCallback?>();
128+
final onMessageSecondaryTap =
129+
context.read<OnMessageSecondaryTapCallback?>();
128130
final isSentByMe = context.read<UserID>() == message.authorId;
129131

130132
final curvedAnimation = CurvedAnimation(
@@ -134,7 +136,7 @@ class ChatMessage extends StatelessWidget {
134136

135137
final resolvedPadding = padding ?? _resolveDefaultPadding(context);
136138

137-
final Widget messageWidget = Column(
139+
final messageWidget = Column(
138140
mainAxisSize: MainAxisSize.min,
139141
children: [
140142
if (headerWidget != null)
@@ -163,6 +165,13 @@ class ChatMessage extends StatelessWidget {
163165
index: index,
164166
details: details,
165167
),
168+
onSecondaryTapUp:
169+
(details) => onMessageSecondaryTap?.call(
170+
context,
171+
message,
172+
index: index,
173+
details: details,
174+
),
166175
child: FadeTransition(
167176
opacity: curvedAnimation,
168177
child: SizeTransition(

packages/flutter_chat_ui/lib/src/utils/typedefs.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ typedef OnMessageLongPressCallback =
2929
LongPressStartDetails details,
3030
});
3131

32+
/// Callback signature for when a message is right-clicked (secondary tapped).
33+
/// [context] is the BuildContext from the widget tree where the long press occurs.
34+
/// Provides the long-pressed [message], its [index], and [LongPressStartDetails].
35+
typedef OnMessageSecondaryTapCallback =
36+
void Function(
37+
BuildContext context,
38+
Message message, {
39+
int index,
40+
TapUpDetails details,
41+
});
42+
3243
/// Callback signature for when the user attempts to send a message.
3344
/// Provides the [text] entered by the user.
3445
typedef OnMessageSendCallback = void Function(String text);

0 commit comments

Comments
 (0)