use MessageWidget.copyWith in actions modal
This commit is contained in:
@@ -15,6 +15,7 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
const MessageActionsModal({
|
const MessageActionsModal({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.message,
|
required this.message,
|
||||||
|
required this.messageWidget,
|
||||||
required this.messageTheme,
|
required this.messageTheme,
|
||||||
this.showReactions = true,
|
this.showReactions = true,
|
||||||
this.showDeleteMessage = true,
|
this.showDeleteMessage = true,
|
||||||
@@ -27,18 +28,15 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
this.showThreadReplyMessage = true,
|
this.showThreadReplyMessage = true,
|
||||||
this.showFlagButton = true,
|
this.showFlagButton = true,
|
||||||
this.showPinButton = true,
|
this.showPinButton = true,
|
||||||
this.showPinHighlight = false,
|
|
||||||
this.showUserAvatar = DisplayWidget.show,
|
|
||||||
this.editMessageInputBuilder,
|
this.editMessageInputBuilder,
|
||||||
this.messageShape,
|
|
||||||
this.attachmentShape,
|
|
||||||
this.reverse = false,
|
this.reverse = false,
|
||||||
this.customActions = const [],
|
this.customActions = const [],
|
||||||
this.attachmentBorderRadiusGeometry,
|
|
||||||
this.onCopyTap,
|
this.onCopyTap,
|
||||||
this.textBuilder,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// Widget that shows the message
|
||||||
|
final Widget messageWidget;
|
||||||
|
|
||||||
/// Builder for edit message
|
/// Builder for edit message
|
||||||
final Widget Function(BuildContext, Message)? editMessageInputBuilder;
|
final Widget Function(BuildContext, Message)? editMessageInputBuilder;
|
||||||
|
|
||||||
@@ -84,30 +82,12 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
/// Flag for showing pin action
|
/// Flag for showing pin action
|
||||||
final bool showPinButton;
|
final bool showPinButton;
|
||||||
|
|
||||||
/// Display Pin Highlight
|
|
||||||
final bool showPinHighlight;
|
|
||||||
|
|
||||||
/// Flag for reversing message
|
/// Flag for reversing message
|
||||||
final bool reverse;
|
final bool reverse;
|
||||||
|
|
||||||
/// [ShapeBorder] to apply to the widget
|
|
||||||
final ShapeBorder? messageShape;
|
|
||||||
|
|
||||||
/// [ShapeBorder] to apply to attachment
|
|
||||||
final ShapeBorder? attachmentShape;
|
|
||||||
|
|
||||||
/// Enum for displaying user avatar
|
|
||||||
final DisplayWidget showUserAvatar;
|
|
||||||
|
|
||||||
/// [BorderRadius] for attachment border
|
|
||||||
final BorderRadius? attachmentBorderRadiusGeometry;
|
|
||||||
|
|
||||||
/// List of custom actions
|
/// List of custom actions
|
||||||
final List<MessageAction> customActions;
|
final List<MessageAction> customActions;
|
||||||
|
|
||||||
/// Customize the MessageWidget textBuilder
|
|
||||||
final Widget Function(BuildContext context, Message message)? textBuilder;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageActionsModalState createState() => _MessageActionsModalState();
|
_MessageActionsModalState createState() => _MessageActionsModalState();
|
||||||
}
|
}
|
||||||
@@ -142,9 +122,6 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
|||||||
? 1
|
? 1
|
||||||
: (roughSentenceSize == 0 ? 1 : (roughSentenceSize / roughMaxSize));
|
: (roughSentenceSize == 0 ? 1 : (roughSentenceSize / roughMaxSize));
|
||||||
|
|
||||||
final hasFileAttachment =
|
|
||||||
widget.message.attachments.any((it) => it.type == 'file') == true;
|
|
||||||
|
|
||||||
final streamChatThemeData = StreamChatTheme.of(context);
|
final streamChatThemeData = StreamChatTheme.of(context);
|
||||||
|
|
||||||
final numberOfReactions = streamChatThemeData.reactionIcons.length;
|
final numberOfReactions = streamChatThemeData.reactionIcons.length;
|
||||||
@@ -178,41 +155,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
IgnorePointer(
|
IgnorePointer(
|
||||||
child: MessageWidget(
|
child: widget.messageWidget,
|
||||||
key: const Key('MessageWidget'),
|
|
||||||
reverse: widget.reverse,
|
|
||||||
attachmentBorderRadiusGeometry: widget
|
|
||||||
.attachmentBorderRadiusGeometry
|
|
||||||
?.mirrorBorderIfReversed(reverse: !widget.reverse),
|
|
||||||
message: widget.message.copyWith(
|
|
||||||
text: widget.message.text!.length > 200
|
|
||||||
// ignore: lines_longer_than_80_chars
|
|
||||||
? '${widget.message.text!.substring(0, 200)}...'
|
|
||||||
: widget.message.text,
|
|
||||||
),
|
|
||||||
messageTheme: widget.messageTheme,
|
|
||||||
showReactions: false,
|
|
||||||
showUsername: false,
|
|
||||||
showReplyMessage: false,
|
|
||||||
showUserAvatar: widget.showUserAvatar,
|
|
||||||
attachmentPadding: EdgeInsets.all(
|
|
||||||
hasFileAttachment ? 4 : 2,
|
|
||||||
),
|
|
||||||
showTimestamp: false,
|
|
||||||
translateUserAvatar: false,
|
|
||||||
padding: const EdgeInsets.all(0),
|
|
||||||
textPadding: EdgeInsets.symmetric(
|
|
||||||
vertical: 8,
|
|
||||||
horizontal: widget.message.text!.isOnlyEmoji ? 0 : 16.0,
|
|
||||||
),
|
|
||||||
showReactionPickerIndicator: widget.showReactions &&
|
|
||||||
(widget.message.status == MessageSendingStatus.sent),
|
|
||||||
showSendingIndicator: false,
|
|
||||||
shape: widget.messageShape,
|
|
||||||
attachmentShape: widget.attachmentShape,
|
|
||||||
showPinHighlight: false,
|
|
||||||
textBuilder: widget.textBuilder,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Padding(
|
Padding(
|
||||||
|
|||||||
@@ -1023,19 +1023,30 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
builder: (context) => StreamChannel(
|
builder: (context) => StreamChannel(
|
||||||
channel: channel,
|
channel: channel,
|
||||||
child: MessageActionsModal(
|
child: MessageActionsModal(
|
||||||
textBuilder: widget.textBuilder,
|
messageWidget: widget.copyWith(
|
||||||
|
key: const Key('MessageWidget'),
|
||||||
|
message: widget.message.copyWith(
|
||||||
|
text: widget.message.text!.length > 200
|
||||||
|
? '${widget.message.text!.substring(0, 200)}...'
|
||||||
|
: widget.message.text,
|
||||||
|
),
|
||||||
|
showReactions: false,
|
||||||
|
showUsername: false,
|
||||||
|
showTimestamp: false,
|
||||||
|
translateUserAvatar: false,
|
||||||
|
showSendingIndicator: false,
|
||||||
|
padding: const EdgeInsets.all(0),
|
||||||
|
showReactionPickerIndicator: widget.showReactions &&
|
||||||
|
(widget.message.status == MessageSendingStatus.sent),
|
||||||
|
showPinHighlight: false,
|
||||||
|
showUserAvatar:
|
||||||
|
widget.message.user!.id == channel.client.state.user!.id
|
||||||
|
? DisplayWidget.gone
|
||||||
|
: DisplayWidget.show,
|
||||||
|
),
|
||||||
onCopyTap: (message) =>
|
onCopyTap: (message) =>
|
||||||
Clipboard.setData(ClipboardData(text: message.text)),
|
Clipboard.setData(ClipboardData(text: message.text)),
|
||||||
attachmentBorderRadiusGeometry:
|
|
||||||
widget.attachmentBorderRadiusGeometry as BorderRadius?,
|
|
||||||
showUserAvatar:
|
|
||||||
widget.message.user!.id == channel.client.state.user!.id
|
|
||||||
? DisplayWidget.gone
|
|
||||||
: DisplayWidget.show,
|
|
||||||
messageTheme: widget.messageTheme,
|
messageTheme: widget.messageTheme,
|
||||||
messageShape: widget.shape ?? _getDefaultShape(context),
|
|
||||||
attachmentShape: widget.attachmentShape ??
|
|
||||||
_getDefaultAttachmentShape(context),
|
|
||||||
reverse: widget.reverse,
|
reverse: widget.reverse,
|
||||||
showDeleteMessage: widget.showDeleteMessage || isDeleteFailed,
|
showDeleteMessage: widget.showDeleteMessage || isDeleteFailed,
|
||||||
message: widget.message,
|
message: widget.message,
|
||||||
@@ -1106,28 +1117,6 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeBorder _getDefaultAttachmentShape(BuildContext context) {
|
|
||||||
final hasFiles =
|
|
||||||
widget.message.attachments.any((it) => it.type == 'file') == true;
|
|
||||||
return RoundedRectangleBorder(
|
|
||||||
side: hasFiles
|
|
||||||
? widget.attachmentBorderSide ??
|
|
||||||
BorderSide(
|
|
||||||
color: _streamChatTheme.colorTheme.greyWhisper,
|
|
||||||
)
|
|
||||||
: BorderSide.none,
|
|
||||||
borderRadius: widget.attachmentBorderRadiusGeometry ?? BorderRadius.zero,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ShapeBorder _getDefaultShape(BuildContext context) => RoundedRectangleBorder(
|
|
||||||
side: widget.borderSide ??
|
|
||||||
BorderSide(
|
|
||||||
color: _streamChatTheme.colorTheme.greyWhisper,
|
|
||||||
),
|
|
||||||
borderRadius: widget.borderRadiusGeometry ?? BorderRadius.zero,
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _parseAttachments() {
|
Widget _parseAttachments() {
|
||||||
final attachmentGroups = <String, List<Attachment>>{};
|
final attachmentGroups = <String, List<Attachment>>{};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user