fix longpress gesturedetector on message

This commit is contained in:
Salvatore Giordano
2021-01-04 12:08:14 +01:00
parent d0c4656973
commit 041c1930c2
+179 -178
View File
@@ -260,174 +260,181 @@ class _MessageWidgetState extends State<MessageWidget> {
true; true;
return Portal( return Portal(
child: Padding( child: GestureDetector(
padding: widget.padding ?? EdgeInsets.all(8), onLongPress: () => onLongPress(context),
child: Transform( child: Padding(
alignment: Alignment.center, padding: widget.padding ?? EdgeInsets.all(8),
transform: Matrix4.rotationY(widget.reverse ? pi : 0), child: Transform(
child: FractionallySizedBox( alignment: Alignment.center,
alignment: Alignment.centerLeft, transform: Matrix4.rotationY(widget.reverse ? pi : 0),
widthFactor: 0.75, child: FractionallySizedBox(
child: Column( alignment: Alignment.centerLeft,
crossAxisAlignment: CrossAxisAlignment.start, widthFactor: 0.75,
mainAxisSize: MainAxisSize.min, child: Column(
children: <Widget>[ crossAxisAlignment: CrossAxisAlignment.start,
Stack( mainAxisSize: MainAxisSize.min,
clipBehavior: Clip.none, children: <Widget>[
alignment: AlignmentDirectional.bottomStart, Stack(
children: [ clipBehavior: Clip.none,
Column( alignment: AlignmentDirectional.bottomStart,
crossAxisAlignment: CrossAxisAlignment.start, children: [
mainAxisSize: MainAxisSize.min, Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Row( mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start, children: [
crossAxisAlignment: CrossAxisAlignment.end, Row(
mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[ crossAxisAlignment: CrossAxisAlignment.end,
if (widget.showUserAvatar == DisplayWidget.show) mainAxisSize: MainAxisSize.min,
_buildUserAvatar(), children: <Widget>[
SizedBox(width: 6), if (widget.showUserAvatar == DisplayWidget.show)
if (widget.showUserAvatar == DisplayWidget.hide) _buildUserAvatar(),
SizedBox( SizedBox(width: 6),
width: widget.messageTheme.avatarTheme if (widget.showUserAvatar == DisplayWidget.hide)
.constraints.maxWidth + SizedBox(
8, width: widget.messageTheme.avatarTheme
), .constraints.maxWidth +
Flexible( 8,
child: PortalEntry(
portal: Container(
transform:
Matrix4.translationValues(-16, 2, 0),
child: _buildReactionIndicator(context),
constraints:
BoxConstraints(maxWidth: 22 * 6.0),
), ),
portalAnchor: Alignment(-1.0, -1.0), Flexible(
childAnchor: Alignment(1, -1.0), child: PortalEntry(
child: Stack( portal: Container(
clipBehavior: Clip.none, transform:
children: [ Matrix4.translationValues(-16, 2, 0),
Padding( child: _buildReactionIndicator(context),
padding: widget.showReactions constraints:
? EdgeInsets.only( BoxConstraints(maxWidth: 22 * 6.0),
top: widget.message.reactionCounts ),
?.isNotEmpty == portalAnchor: Alignment(-1.0, -1.0),
true childAnchor: Alignment(1, -1.0),
? 18 child: Stack(
: 0, clipBehavior: Clip.none,
) children: [
: EdgeInsets.zero, Padding(
child: (widget.message.isDeleted && padding: widget.showReactions
!isFailedState) ? EdgeInsets.only(
? Transform( top: widget
alignment: Alignment.center, .message
transform: Matrix4.rotationY( .reactionCounts
widget.reverse ? pi : 0), ?.isNotEmpty ==
child: DeletedMessage( true
reverse: widget.reverse, ? 18
borderRadiusGeometry: : 0,
widget.borderRadiusGeometry, )
borderSide: widget.borderSide, : EdgeInsets.zero,
shape: widget.shape, child: (widget.message.isDeleted &&
messageTheme: !isFailedState)
widget.messageTheme, ? Transform(
), alignment: Alignment.center,
) transform: Matrix4.rotationY(
: Material( widget.reverse ? pi : 0),
clipBehavior: Clip.antiAlias, child: DeletedMessage(
shape: widget.shape ?? reverse: widget.reverse,
RoundedRectangleBorder( borderRadiusGeometry: widget
side: isOnlyEmoji .borderRadiusGeometry,
? BorderSide.none borderSide: widget.borderSide,
: widget.borderSide ?? shape: widget.shape,
BorderSide( messageTheme:
color: Theme.of(context) widget.messageTheme,
.brightness == ),
Brightness )
.dark : Material(
? StreamChatTheme.of( clipBehavior: Clip.antiAlias,
context) shape: widget.shape ??
.colorTheme RoundedRectangleBorder(
.white side: isOnlyEmoji
.withAlpha( ? BorderSide.none
24) : widget.borderSide ??
: StreamChatTheme.of( BorderSide(
context) color: Theme.of(context)
.colorTheme .brightness ==
.black Brightness
.withAlpha( .dark
24), ? StreamChatTheme.of(
), context)
borderRadius: widget .colorTheme
.borderRadiusGeometry ?? .white
BorderRadius.zero, .withAlpha(
24)
: StreamChatTheme.of(
context)
.colorTheme
.black
.withAlpha(
24),
),
borderRadius: widget
.borderRadiusGeometry ??
BorderRadius.zero,
),
color: _getBackgroundColor(),
child: Padding(
padding: EdgeInsets.all(
hasFiles ? 2.0 : 0.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
mainAxisSize:
MainAxisSize.min,
children: <Widget>[
..._parseAttachments(
context),
if (widget.message.text
.trim()
.isNotEmpty &&
!isGiphy)
_buildTextBubble(
context),
],
), ),
color: _getBackgroundColor(),
child: Padding(
padding: EdgeInsets.all(
hasFiles ? 2.0 : 0.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisSize:
MainAxisSize.min,
children: <Widget>[
..._parseAttachments(
context),
if (widget.message.text
.trim()
.isNotEmpty &&
!isGiphy)
_buildTextBubble(context),
],
), ),
), ),
), ),
), if (widget.showReactionPickerIndicator)
if (widget.showReactionPickerIndicator) Positioned(
Positioned( right: 0,
right: 0, top: -6,
top: -6, child: Transform(
child: Transform( transform: Matrix4.rotationY(
transform: Matrix4.rotationY( widget.reverse ? pi : 0),
widget.reverse ? pi : 0), child: CustomPaint(
child: CustomPaint( painter: ReactionBubblePainter(
painter: ReactionBubblePainter( widget.messageTheme
widget.messageTheme .reactionsBackgroundColor,
.reactionsBackgroundColor, widget.messageTheme
widget.messageTheme .reactionsBorderColor,
.reactionsBorderColor, ),
), ),
), ),
), ),
), ],
], ),
), ),
), ),
), ],
],
),
if (showBottomRow) SizedBox(height: 20.0),
],
),
if (showBottomRow) _buildBottomRow(leftPadding),
if (isFailedState)
Positioned(
left: widget.reverse ? -3 : null,
right: widget.reverse ? null : -9,
bottom: showBottomRow ? 20 : 0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
), ),
child: StreamSvgIcon.error(size: 20), if (showBottomRow) SizedBox(height: 20.0),
), ],
), ),
], if (showBottomRow) _buildBottomRow(leftPadding),
), if (isFailedState)
], Positioned(
left: widget.reverse ? -3 : null,
right: widget.reverse ? null : -9,
bottom: showBottomRow ? 20 : 0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: StreamSvgIcon.error(size: 20),
),
),
],
),
],
),
), ),
), ),
), ),
@@ -739,23 +746,20 @@ class _MessageWidgetState extends State<MessageWidget> {
}) { }) {
final attachmentShape = final attachmentShape =
widget.attachmentShape ?? widget.shape ?? _getDefaultShape(context); widget.attachmentShape ?? widget.shape ?? _getDefaultShape(context);
return GestureDetector( return Material(
onLongPress: () => onLongPress(context), color: _getBackgroundColor(),
child: Material( clipBehavior: Clip.antiAlias,
color: _getBackgroundColor(), shape: attachmentShape,
clipBehavior: Clip.antiAlias, child: Padding(
shape: attachmentShape, padding: widget.attachmentPadding,
child: Padding( child: Material(
padding: widget.attachmentPadding, clipBehavior: Clip.hardEdge,
child: Material( shape: attachmentShape,
clipBehavior: Clip.hardEdge, type: MaterialType.transparency,
shape: attachmentShape, child: Transform(
type: MaterialType.transparency, transform: Matrix4.rotationY(widget.reverse ? pi : 0),
child: Transform( alignment: Alignment.center,
transform: Matrix4.rotationY(widget.reverse ? pi : 0), child: attachmentWidget,
alignment: Alignment.center,
child: attachmentWidget,
),
), ),
), ),
), ),
@@ -854,10 +858,7 @@ class _MessageWidgetState extends State<MessageWidget> {
], ],
), ),
); );
return GestureDetector( return child;
onLongPress: () => onLongPress(context),
child: child,
);
} }
bool get isOnlyEmoji => bool get isOnlyEmoji =>