@@ -25,7 +25,7 @@ import 'package:video_compress/video_compress.dart';
|
||||
import 'extension.dart';
|
||||
|
||||
import '../stream_chat_flutter.dart';
|
||||
import 'reply_message_widget.dart';
|
||||
import 'quoted_message_widget.dart';
|
||||
import 'stream_channel.dart';
|
||||
|
||||
typedef FileUploader = Future<String> Function(PlatformFile, Channel);
|
||||
@@ -2015,7 +2015,9 @@ class MessageInputState extends State<MessageInput> {
|
||||
|
||||
textEditingController.clear();
|
||||
_attachments.clear();
|
||||
widget.onQuotedMessageCleared();
|
||||
if (widget.onQuotedMessageCleared != null) {
|
||||
widget.onQuotedMessageCleared();
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_messageIsPresent = false;
|
||||
|
||||
+35
-32
@@ -11,7 +11,7 @@ import 'package:jiffy/jiffy.dart';
|
||||
import 'package:stream_chat_flutter/src/message_actions_modal.dart';
|
||||
import 'package:stream_chat_flutter/src/message_reactions_modal.dart';
|
||||
import 'package:stream_chat_flutter/src/reaction_bubble.dart';
|
||||
import 'package:stream_chat_flutter/src/reply_message_widget.dart';
|
||||
import 'package:stream_chat_flutter/src/quoted_message_widget.dart';
|
||||
import 'package:stream_chat_flutter/src/url_attachment.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
@@ -356,37 +356,39 @@ class _MessageWidgetState extends State<MessageWidget> {
|
||||
widget.messageTheme,
|
||||
),
|
||||
)
|
||||
: GestureDetector(
|
||||
onLongPress: () =>
|
||||
onLongPress(context),
|
||||
child: Material(
|
||||
clipBehavior:
|
||||
Clip.antiAlias,
|
||||
shape: widget.shape ??
|
||||
RoundedRectangleBorder(
|
||||
side: isOnlyEmoji
|
||||
? BorderSide.none
|
||||
: widget.borderSide ??
|
||||
BorderSide(
|
||||
color: Theme.of(context).brightness ==
|
||||
Brightness
|
||||
.dark
|
||||
? StreamChatTheme.of(context)
|
||||
.colorTheme
|
||||
.white
|
||||
.withAlpha(
|
||||
24)
|
||||
: StreamChatTheme.of(context)
|
||||
.colorTheme
|
||||
.black
|
||||
.withAlpha(24),
|
||||
),
|
||||
borderRadius: widget
|
||||
.borderRadiusGeometry ??
|
||||
BorderRadius.zero,
|
||||
),
|
||||
color:
|
||||
_getBackgroundColor(),
|
||||
: Material(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: widget.shape ??
|
||||
RoundedRectangleBorder(
|
||||
side: isOnlyEmoji
|
||||
? BorderSide.none
|
||||
: widget.borderSide ??
|
||||
BorderSide(
|
||||
color: Theme.of(context)
|
||||
.brightness ==
|
||||
Brightness
|
||||
.dark
|
||||
? StreamChatTheme.of(
|
||||
context)
|
||||
.colorTheme
|
||||
.white
|
||||
.withAlpha(
|
||||
24)
|
||||
: StreamChatTheme.of(
|
||||
context)
|
||||
.colorTheme
|
||||
.black
|
||||
.withAlpha(
|
||||
24),
|
||||
),
|
||||
borderRadius: widget
|
||||
.borderRadiusGeometry ??
|
||||
BorderRadius.zero,
|
||||
),
|
||||
color: _getBackgroundColor(),
|
||||
child: InkWell(
|
||||
onLongPress: () =>
|
||||
onLongPress(context),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(
|
||||
hasFiles ? 2.0 : 0.0),
|
||||
@@ -399,6 +401,7 @@ class _MessageWidgetState extends State<MessageWidget> {
|
||||
children: <Widget>[
|
||||
if (_hasQuotedMessage)
|
||||
QuotedMessageWidget(
|
||||
onTap: () {},
|
||||
message: widget
|
||||
.message
|
||||
.quotedMessage,
|
||||
|
||||
@@ -12,8 +12,9 @@ import 'message_text.dart';
|
||||
import 'stream_chat_theme.dart';
|
||||
import 'user_avatar.dart';
|
||||
import 'utils.dart';
|
||||
import 'extension.dart';
|
||||
|
||||
typedef ReplyMessageAttachmentThumbnailBuilder = Widget Function(
|
||||
typedef QuotedMessageAttachmentThumbnailBuilder = Widget Function(
|
||||
BuildContext,
|
||||
Attachment,
|
||||
);
|
||||
@@ -80,9 +81,11 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
final int textLimit;
|
||||
|
||||
/// Map that defines a thumbnail builder for an attachment type
|
||||
final Map<String, ReplyMessageAttachmentThumbnailBuilder>
|
||||
final Map<String, QuotedMessageAttachmentThumbnailBuilder>
|
||||
attachmentThumbnailBuilders;
|
||||
|
||||
final GestureTapCallback onTap;
|
||||
|
||||
///
|
||||
QuotedMessageWidget({
|
||||
Key key,
|
||||
@@ -92,6 +95,7 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
this.showBorder = false,
|
||||
this.textLimit = 170,
|
||||
this.attachmentThumbnailBuilders,
|
||||
this.onTap,
|
||||
}) : super(key: key);
|
||||
|
||||
bool get _hasAttachments => message.attachments?.isNotEmpty == true;
|
||||
@@ -104,32 +108,54 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 6, right: 4, left: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: _buildMessage(context)),
|
||||
SizedBox(width: 4),
|
||||
_buildUserAvatar(),
|
||||
],
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 6, right: 4, left: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: _buildMessage(context)),
|
||||
SizedBox(width: 4),
|
||||
_buildUserAvatar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMessage(BuildContext context) {
|
||||
final isOnlyEmoji =
|
||||
message.text.characters.every((c) => Emoji.byChar(c) != null);
|
||||
var msg = _hasAttachments && !_containsText
|
||||
? message.copyWith(text: message.attachments.last?.title ?? '')
|
||||
: message;
|
||||
if (msg.text.length > textLimit) {
|
||||
msg = msg.copyWith(text: '${msg.text.substring(0, textLimit - 3)}...');
|
||||
}
|
||||
|
||||
final children = [
|
||||
if (_hasAttachments) ...[
|
||||
_parseAttachments(context),
|
||||
SizedBox(width: 8),
|
||||
],
|
||||
Flexible(child: _buildTextMessage()),
|
||||
];
|
||||
if (_hasAttachments) _parseAttachments(context),
|
||||
if (msg.text.isNotEmpty)
|
||||
Flexible(
|
||||
child: Transform(
|
||||
transform: Matrix4.rotationY(reverse ? pi : 0),
|
||||
alignment: Alignment.center,
|
||||
child: MessageText(
|
||||
message: msg,
|
||||
messageTheme: isOnlyEmoji && _containsText
|
||||
? messageTheme.copyWith(
|
||||
messageText: messageTheme.messageText.copyWith(
|
||||
fontSize: 24,
|
||||
))
|
||||
: messageTheme,
|
||||
),
|
||||
),
|
||||
),
|
||||
].insertBetween(const SizedBox(width: 8));
|
||||
|
||||
return Container(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: 48.0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _getBackgroundColor(context),
|
||||
border: showBorder
|
||||
@@ -146,6 +172,7 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
reverse ? MainAxisAlignment.end : MainAxisAlignment.start,
|
||||
children: reverse ? children.reversed.toList() : children,
|
||||
@@ -153,30 +180,6 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextMessage() {
|
||||
final isOnlyEmoji =
|
||||
message.text.characters.every((c) => Emoji.byChar(c) != null);
|
||||
var msg = _hasAttachments && !_containsText
|
||||
? message.copyWith(text: message.attachments.last?.title ?? '')
|
||||
: message;
|
||||
if (msg.text.length > textLimit) {
|
||||
msg = msg.copyWith(text: '${msg.text.substring(0, textLimit - 3)}...');
|
||||
}
|
||||
return Transform(
|
||||
transform: Matrix4.rotationY(reverse ? pi : 0),
|
||||
alignment: Alignment.center,
|
||||
child: MessageText(
|
||||
message: msg,
|
||||
messageTheme: isOnlyEmoji && _containsText
|
||||
? messageTheme.copyWith(
|
||||
messageText: messageTheme.messageText.copyWith(
|
||||
fontSize: 24,
|
||||
))
|
||||
: messageTheme,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUrlAttachment(Attachment attachment) {
|
||||
final size = Size(32, 32);
|
||||
if (attachment.thumbUrl != null) {
|
||||
@@ -208,7 +211,7 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
);
|
||||
child = _buildUrlAttachment(attachment);
|
||||
} else {
|
||||
ReplyMessageAttachmentThumbnailBuilder attachmentBuilder;
|
||||
QuotedMessageAttachmentThumbnailBuilder attachmentBuilder;
|
||||
attachment = message.attachments.last;
|
||||
if (attachmentThumbnailBuilders?.containsKey(attachment?.type) == true) {
|
||||
attachmentBuilder = attachmentThumbnailBuilders[attachment?.type];
|
||||
@@ -219,6 +222,7 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
}
|
||||
child = attachmentBuilder(context, attachment);
|
||||
}
|
||||
child = AbsorbPointer(child: child);
|
||||
return Transform(
|
||||
transform: Matrix4.rotationY(reverse ? pi : 0),
|
||||
alignment: Alignment.center,
|
||||
@@ -258,7 +262,7 @@ class QuotedMessageWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, ReplyMessageAttachmentThumbnailBuilder>
|
||||
Map<String, QuotedMessageAttachmentThumbnailBuilder>
|
||||
get _defaultAttachmentBuilder {
|
||||
return {
|
||||
'image': (_, attachment) {
|
||||
Reference in New Issue
Block a user