Handle onQuotedMessageTap
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -181,7 +181,6 @@ class MessageListView extends StatefulWidget {
|
|||||||
class _MessageListViewState extends State<MessageListView> {
|
class _MessageListViewState extends State<MessageListView> {
|
||||||
ItemScrollController _scrollController;
|
ItemScrollController _scrollController;
|
||||||
bool _bottomWasVisible = false;
|
bool _bottomWasVisible = false;
|
||||||
bool _topWasVisible = false;
|
|
||||||
Function _onThreadTap;
|
Function _onThreadTap;
|
||||||
bool _showScrollToBottom = false;
|
bool _showScrollToBottom = false;
|
||||||
ItemPositionsListener _itemPositionListener;
|
ItemPositionsListener _itemPositionListener;
|
||||||
@@ -772,6 +771,17 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
bottom: index == 0 ? 30 : (isNextUser ? 2 : 7),
|
bottom: index == 0 ? 30 : (isNextUser ? 2 : 7),
|
||||||
top: 3,
|
top: 3,
|
||||||
),
|
),
|
||||||
|
onQuotedMessageTap: (quotedMessageId) {
|
||||||
|
if (messages.map((e) => e.id).contains(quotedMessageId)) {
|
||||||
|
final index = messages.indexWhere((m) => m.id == quotedMessageId);
|
||||||
|
_scrollController?.scrollTo(
|
||||||
|
index: index,
|
||||||
|
duration: const Duration(milliseconds: 350),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
streamChannel.loadChannelAtMessage(quotedMessageId);
|
||||||
|
}
|
||||||
|
},
|
||||||
showInChannelIndicator: widget.parentMessage == null,
|
showInChannelIndicator: widget.parentMessage == null,
|
||||||
showThreadReplyIndicator: widget.parentMessage == null,
|
showThreadReplyIndicator: widget.parentMessage == null,
|
||||||
showUsername: !isMyMessage && !isNextUser,
|
showUsername: !isMyMessage && !isNextUser,
|
||||||
|
|||||||
+88
-84
@@ -20,6 +20,7 @@ import 'message_text.dart';
|
|||||||
import 'extension.dart';
|
import 'extension.dart';
|
||||||
|
|
||||||
typedef AttachmentBuilder = Widget Function(BuildContext, Message, Attachment);
|
typedef AttachmentBuilder = Widget Function(BuildContext, Message, Attachment);
|
||||||
|
typedef OnQuotedMessageTap = void Function(String);
|
||||||
|
|
||||||
/// The display behaviour of a widget
|
/// The display behaviour of a widget
|
||||||
enum DisplayWidget {
|
enum DisplayWidget {
|
||||||
@@ -135,6 +136,9 @@ class MessageWidget extends StatefulWidget {
|
|||||||
/// Center user avatar with bottom of the message
|
/// Center user avatar with bottom of the message
|
||||||
final bool translateUserAvatar;
|
final bool translateUserAvatar;
|
||||||
|
|
||||||
|
/// Function called when quotedMessage is tapped
|
||||||
|
final OnQuotedMessageTap onQuotedMessageTap;
|
||||||
|
|
||||||
///
|
///
|
||||||
MessageWidget({
|
MessageWidget({
|
||||||
Key key,
|
Key key,
|
||||||
@@ -177,6 +181,7 @@ class MessageWidget extends StatefulWidget {
|
|||||||
),
|
),
|
||||||
this.attachmentPadding = EdgeInsets.zero,
|
this.attachmentPadding = EdgeInsets.zero,
|
||||||
this.allRead = false,
|
this.allRead = false,
|
||||||
|
this.onQuotedMessageTap,
|
||||||
}) : attachmentBuilders = {
|
}) : attachmentBuilders = {
|
||||||
'image': (context, message, attachment) {
|
'image': (context, message, attachment) {
|
||||||
return ImageAttachment(
|
return ImageAttachment(
|
||||||
@@ -338,97 +343,81 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
: 0,
|
: 0,
|
||||||
)
|
)
|
||||||
: EdgeInsets.zero,
|
: EdgeInsets.zero,
|
||||||
child:
|
child: (widget.message.isDeleted &&
|
||||||
(widget.message.isDeleted &&
|
!isFailedState)
|
||||||
!isFailedState)
|
? Transform(
|
||||||
? Transform(
|
alignment: Alignment.center,
|
||||||
alignment: Alignment.center,
|
transform: Matrix4.rotationY(
|
||||||
transform: Matrix4.rotationY(
|
widget.reverse ? pi : 0),
|
||||||
widget.reverse ? pi : 0),
|
child: DeletedMessage(
|
||||||
child: DeletedMessage(
|
reverse: widget.reverse,
|
||||||
reverse: widget.reverse,
|
borderRadiusGeometry:
|
||||||
borderRadiusGeometry: widget
|
widget.borderRadiusGeometry,
|
||||||
.borderRadiusGeometry,
|
borderSide: widget.borderSide,
|
||||||
borderSide:
|
shape: widget.shape,
|
||||||
widget.borderSide,
|
messageTheme:
|
||||||
shape: widget.shape,
|
widget.messageTheme,
|
||||||
messageTheme:
|
),
|
||||||
widget.messageTheme,
|
)
|
||||||
),
|
: Material(
|
||||||
)
|
clipBehavior: Clip.antiAlias,
|
||||||
: Material(
|
shape: widget.shape ??
|
||||||
clipBehavior: Clip.antiAlias,
|
RoundedRectangleBorder(
|
||||||
shape: widget.shape ??
|
side: isOnlyEmoji
|
||||||
RoundedRectangleBorder(
|
? BorderSide.none
|
||||||
side: isOnlyEmoji
|
: widget.borderSide ??
|
||||||
? BorderSide.none
|
BorderSide(
|
||||||
: widget.borderSide ??
|
color: Theme.of(context)
|
||||||
BorderSide(
|
.brightness ==
|
||||||
color: Theme.of(context)
|
Brightness
|
||||||
.brightness ==
|
.dark
|
||||||
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),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment:
|
|
||||||
CrossAxisAlignment
|
|
||||||
.start,
|
|
||||||
mainAxisSize:
|
|
||||||
MainAxisSize.min,
|
|
||||||
children: <Widget>[
|
|
||||||
if (_hasQuotedMessage)
|
|
||||||
QuotedMessageWidget(
|
|
||||||
onTap: () {},
|
|
||||||
message: widget
|
|
||||||
.message
|
|
||||||
.quotedMessage,
|
|
||||||
messageTheme: isMyMessage
|
|
||||||
? StreamChatTheme.of(
|
? StreamChatTheme.of(
|
||||||
context)
|
context)
|
||||||
.otherMessageTheme
|
.colorTheme
|
||||||
|
.white
|
||||||
|
.withAlpha(
|
||||||
|
24)
|
||||||
: StreamChatTheme.of(
|
: StreamChatTheme.of(
|
||||||
context)
|
context)
|
||||||
.ownMessageTheme,
|
.colorTheme
|
||||||
reverse: widget
|
.black
|
||||||
.reverse,
|
.withAlpha(
|
||||||
|
24),
|
||||||
),
|
),
|
||||||
..._parseAttachments(
|
borderRadius: widget
|
||||||
context),
|
.borderRadiusGeometry ??
|
||||||
if (widget
|
BorderRadius.zero,
|
||||||
.message.text
|
),
|
||||||
.trim()
|
color: _getBackgroundColor(),
|
||||||
.isNotEmpty &&
|
child: InkWell(
|
||||||
!isGiphy)
|
onLongPress: () =>
|
||||||
_buildTextBubble(
|
onLongPress(context),
|
||||||
context),
|
child: Padding(
|
||||||
],
|
padding: EdgeInsets.all(
|
||||||
),
|
hasFiles ? 2.0 : 0.0),
|
||||||
),
|
child: Column(
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment
|
||||||
|
.start,
|
||||||
|
mainAxisSize:
|
||||||
|
MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
if (_hasQuotedMessage)
|
||||||
|
_buildQuotedMessage(
|
||||||
|
isMyMessage),
|
||||||
|
..._parseAttachments(
|
||||||
|
context),
|
||||||
|
if (widget.message.text
|
||||||
|
.trim()
|
||||||
|
.isNotEmpty &&
|
||||||
|
!isGiphy)
|
||||||
|
_buildTextBubble(
|
||||||
|
context),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (widget.showReactionPickerIndicator)
|
if (widget.showReactionPickerIndicator)
|
||||||
Positioned(
|
Positioned(
|
||||||
@@ -480,6 +469,21 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildQuotedMessage(bool isMyMessage) {
|
||||||
|
return QuotedMessageWidget(
|
||||||
|
onTap: () {
|
||||||
|
if (widget.onQuotedMessageTap != null) {
|
||||||
|
widget.onQuotedMessageTap(widget.message.quotedMessageId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
message: widget.message.quotedMessage,
|
||||||
|
messageTheme: isMyMessage
|
||||||
|
? StreamChatTheme.of(context).otherMessageTheme
|
||||||
|
: StreamChatTheme.of(context).ownMessageTheme,
|
||||||
|
reverse: widget.reverse,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildBottomRow(double leftPadding) {
|
Widget _buildBottomRow(double leftPadding) {
|
||||||
final deleted = widget.message.isDeleted;
|
final deleted = widget.message.isDeleted;
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
|
|||||||
Reference in New Issue
Block a user