add usernameBuilder param
This commit is contained in:
@@ -35,6 +35,7 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
this.customActions = const [],
|
this.customActions = const [],
|
||||||
this.attachmentBorderRadiusGeometry,
|
this.attachmentBorderRadiusGeometry,
|
||||||
this.onCopyTap,
|
this.onCopyTap,
|
||||||
|
this.textBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Builder for edit message
|
/// Builder for edit message
|
||||||
@@ -97,6 +98,9 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
/// 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();
|
||||||
}
|
}
|
||||||
@@ -222,6 +226,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
|||||||
showSendingIndicator: false,
|
showSendingIndicator: false,
|
||||||
shape: widget.messageShape,
|
shape: widget.messageShape,
|
||||||
attachmentShape: widget.attachmentShape,
|
attachmentShape: widget.attachmentShape,
|
||||||
|
textBuilder: widget.textBuilder,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
|||||||
@@ -156,8 +156,9 @@ class MessageListView extends StatefulWidget {
|
|||||||
this.onMessageTap,
|
this.onMessageTap,
|
||||||
this.onSystemMessageTap,
|
this.onSystemMessageTap,
|
||||||
this.onAttachmentTap,
|
this.onAttachmentTap,
|
||||||
this.textBuilder,
|
|
||||||
this.onLinkTap,
|
this.onLinkTap,
|
||||||
|
this.textBuilder,
|
||||||
|
this.usernameBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// Function used to build a custom message widget
|
||||||
@@ -259,7 +260,10 @@ class MessageListView extends StatefulWidget {
|
|||||||
final void Function(Message message, Attachment attachment)? onAttachmentTap;
|
final void Function(Message message, Attachment attachment)? onAttachmentTap;
|
||||||
|
|
||||||
/// Customize the MessageWidget textBuilder
|
/// Customize the MessageWidget textBuilder
|
||||||
final void Function(BuildContext context, Message message)? textBuilder;
|
final Widget Function(BuildContext context, Message message)? textBuilder;
|
||||||
|
|
||||||
|
/// Customize the MessageWidget usernameBuilder
|
||||||
|
final Widget Function(BuildContext context, Message message)? usernameBuilder;
|
||||||
|
|
||||||
/// Callback for when link is tapped
|
/// Callback for when link is tapped
|
||||||
final void Function(String link)? onLinkTap;
|
final void Function(String link)? onLinkTap;
|
||||||
@@ -857,8 +861,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
}
|
}
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
textBuilder:
|
textBuilder: widget.textBuilder,
|
||||||
widget.textBuilder as Widget Function(BuildContext, Message)?,
|
usernameBuilder: widget.usernameBuilder,
|
||||||
onLinkTap: widget.onLinkTap,
|
onLinkTap: widget.onLinkTap,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1056,8 +1060,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
onAttachmentTap: widget.onAttachmentTap,
|
onAttachmentTap: widget.onAttachmentTap,
|
||||||
textBuilder:
|
textBuilder: widget.textBuilder,
|
||||||
widget.textBuilder as Widget Function(BuildContext, Message)?,
|
usernameBuilder: widget.usernameBuilder,
|
||||||
onLinkTap: widget.onLinkTap,
|
onLinkTap: widget.onLinkTap,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class MessageReactionsModal extends StatelessWidget {
|
|||||||
this.showUserAvatar = DisplayWidget.show,
|
this.showUserAvatar = DisplayWidget.show,
|
||||||
this.onUserAvatarTap,
|
this.onUserAvatarTap,
|
||||||
this.attachmentBorderRadiusGeometry,
|
this.attachmentBorderRadiusGeometry,
|
||||||
|
this.textBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message to display reactions of
|
/// Message to display reactions of
|
||||||
@@ -52,6 +53,9 @@ class MessageReactionsModal extends StatelessWidget {
|
|||||||
/// [BorderRadius] to apply to attachments
|
/// [BorderRadius] to apply to attachments
|
||||||
final BorderRadius? attachmentBorderRadiusGeometry;
|
final BorderRadius? attachmentBorderRadiusGeometry;
|
||||||
|
|
||||||
|
/// Customize the MessageWidget textBuilder
|
||||||
|
final Widget Function(BuildContext context, Message message)? textBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final size = MediaQuery.of(context).size;
|
final size = MediaQuery.of(context).size;
|
||||||
@@ -157,6 +161,7 @@ class MessageReactionsModal extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
showReactionPickerIndicator: showReactions &&
|
showReactionPickerIndicator: showReactions &&
|
||||||
(message.status == MessageSendingStatus.sent),
|
(message.status == MessageSendingStatus.sent),
|
||||||
|
textBuilder: textBuilder,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (message.latestReactions?.isNotEmpty == true) ...[
|
if (message.latestReactions?.isNotEmpty == true) ...[
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ class MessageWidget extends StatefulWidget {
|
|||||||
this.onQuotedMessageTap,
|
this.onQuotedMessageTap,
|
||||||
this.customActions = const [],
|
this.customActions = const [],
|
||||||
this.onAttachmentTap,
|
this.onAttachmentTap,
|
||||||
|
this.usernameBuilder,
|
||||||
}) : attachmentBuilders = {
|
}) : attachmentBuilders = {
|
||||||
'image': (context, message, attachments) {
|
'image': (context, message, attachments) {
|
||||||
final border = RoundedRectangleBorder(
|
final border = RoundedRectangleBorder(
|
||||||
@@ -265,6 +266,9 @@ class MessageWidget extends StatefulWidget {
|
|||||||
/// Widget builder for building text
|
/// Widget builder for building text
|
||||||
final Widget Function(BuildContext, Message)? textBuilder;
|
final Widget Function(BuildContext, Message)? textBuilder;
|
||||||
|
|
||||||
|
/// Widget builder for building username
|
||||||
|
final Widget Function(BuildContext, Message)? usernameBuilder;
|
||||||
|
|
||||||
/// Function called on long press
|
/// Function called on long press
|
||||||
final void Function(BuildContext, Message)? onMessageActions;
|
final void Function(BuildContext, Message)? onMessageActions;
|
||||||
|
|
||||||
@@ -721,14 +725,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
child: Text(msg, style: widget.messageTheme.replies),
|
child: Text(msg, style: widget.messageTheme.replies),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
if (showUsername)
|
if (showUsername) _buildUsername(usernameKey),
|
||||||
Text(
|
|
||||||
widget.message.user!.name,
|
|
||||||
maxLines: 1,
|
|
||||||
key: usernameKey,
|
|
||||||
style: widget.messageTheme.messageAuthor,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
if (showTimeStamp)
|
if (showTimeStamp)
|
||||||
Text(
|
Text(
|
||||||
Jiffy(widget.message.createdAt.toLocal()).jm,
|
Jiffy(widget.message.createdAt.toLocal()).jm,
|
||||||
@@ -791,6 +788,19 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildUsername(Key usernameKey) {
|
||||||
|
if (widget.usernameBuilder != null) {
|
||||||
|
return widget.usernameBuilder!(context, widget.message);
|
||||||
|
}
|
||||||
|
return Text(
|
||||||
|
widget.message.user!.name,
|
||||||
|
maxLines: 1,
|
||||||
|
key: usernameKey,
|
||||||
|
style: widget.messageTheme.messageAuthor,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildUrlAttachment() {
|
Widget _buildUrlAttachment() {
|
||||||
final urlAttachment = widget.message.attachments
|
final urlAttachment = widget.message.attachments
|
||||||
.firstWhere((element) => element.ogScrapeUrl != null);
|
.firstWhere((element) => element.ogScrapeUrl != null);
|
||||||
@@ -882,6 +892,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
builder: (context) => StreamChannel(
|
builder: (context) => StreamChannel(
|
||||||
channel: channel,
|
channel: channel,
|
||||||
child: MessageActionsModal(
|
child: MessageActionsModal(
|
||||||
|
textBuilder: widget.textBuilder,
|
||||||
onCopyTap: (message) =>
|
onCopyTap: (message) =>
|
||||||
Clipboard.setData(ClipboardData(text: message.text)),
|
Clipboard.setData(ClipboardData(text: message.text)),
|
||||||
attachmentBorderRadiusGeometry:
|
attachmentBorderRadiusGeometry:
|
||||||
@@ -931,6 +942,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
builder: (context) => StreamChannel(
|
builder: (context) => StreamChannel(
|
||||||
channel: channel,
|
channel: channel,
|
||||||
child: MessageReactionsModal(
|
child: MessageReactionsModal(
|
||||||
|
textBuilder: widget.textBuilder,
|
||||||
attachmentBorderRadiusGeometry:
|
attachmentBorderRadiusGeometry:
|
||||||
widget.attachmentBorderRadiusGeometry as BorderRadius?,
|
widget.attachmentBorderRadiusGeometry as BorderRadius?,
|
||||||
showUserAvatar:
|
showUserAvatar:
|
||||||
|
|||||||
Reference in New Issue
Block a user