From d54315cf775df8a79121bd638e976e00254b254b Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 4 Jan 2021 11:54:19 +0100 Subject: [PATCH 1/4] force one reaction --- lib/src/reaction_picker.dart | 10 +++++----- pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/reaction_picker.dart b/lib/src/reaction_picker.dart index 5892a66d..9344b386 100644 --- a/lib/src/reaction_picker.dart +++ b/lib/src/reaction_picker.dart @@ -136,11 +136,11 @@ class _ReactionPickerState extends State /// Add a reaction to the message void sendReaction(BuildContext context, String reactionType) { - StreamChannel.of(context) - .channel - .sendReaction(widget.message, reactionType, extraData: { - 'enforce_unique': true, - }); + StreamChannel.of(context).channel.sendReaction( + widget.message, + reactionType, + enforceUnique: true, + ); pop(); } diff --git a/pubspec.yaml b/pubspec.yaml index 12374291..db646293 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,7 +28,7 @@ dependencies: file_picker: ^2.0.12 image_picker: ^0.6.7+2 flutter_keyboard_visibility: ^3.3.0 - stream_chat: ^0.2.20 + stream_chat: ^0.2.21+2 mime: ^0.9.6+3 video_compress: ^2.1.1 visibility_detector: ^0.1.5 From fa50372f4203a2f0080376c2aa2b229284ce63f5 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 4 Jan 2021 11:55:30 +0100 Subject: [PATCH 2/4] update default reactions --- lib/src/stream_chat_theme.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/stream_chat_theme.dart b/lib/src/stream_chat_theme.dart index 60e37b80..ec469f81 100644 --- a/lib/src/stream_chat_theme.dart +++ b/lib/src/stream_chat_theme.dart @@ -342,19 +342,19 @@ class StreamChatThemeData { assetName: 'Icon_love_reaction.svg', ), ReactionIcon( - type: 'thumbs_up', + type: 'like', assetName: 'Icon_thumbs_up_reaction.svg', ), ReactionIcon( - type: 'thumbs_down', + type: 'sad', assetName: 'Icon_thumbs_down_reaction.svg', ), ReactionIcon( - type: 'lol', + type: 'haha', assetName: 'Icon_LOL_reaction.svg', ), ReactionIcon( - type: 'wut', + type: 'wow', assetName: 'Icon_wut_reaction.svg', ), ], From d0c46569730f33cf0045e75ed398ce4212a2724f Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 4 Jan 2021 12:04:00 +0100 Subject: [PATCH 3/4] cleanup --- lib/src/channel_bottom_sheet.dart | 2 +- lib/src/image_footer.dart | 8 ++------ lib/src/media_list_view.dart | 11 +++-------- lib/src/message_widget.dart | 27 --------------------------- lib/src/stream_chat.dart | 1 - lib/src/stream_chat_theme.dart | 20 +------------------- 6 files changed, 7 insertions(+), 62 deletions(-) diff --git a/lib/src/channel_bottom_sheet.dart b/lib/src/channel_bottom_sheet.dart index d2c7eb04..4bfa3fd0 100644 --- a/lib/src/channel_bottom_sheet.dart +++ b/lib/src/channel_bottom_sheet.dart @@ -5,7 +5,7 @@ import 'channel_info.dart'; import 'option_list_tile.dart'; class ChannelBottomSheet extends StatefulWidget { - VoidCallback onViewInfoTap; + final VoidCallback onViewInfoTap; ChannelBottomSheet({this.onViewInfoTap}); diff --git a/lib/src/image_footer.dart b/lib/src/image_footer.dart index eff6110a..ec92693d 100644 --- a/lib/src/image_footer.dart +++ b/lib/src/image_footer.dart @@ -48,14 +48,10 @@ class ImageFooter extends StatefulWidget { this.message, this.videoPackages, this.mediaSelectedCallBack, - }) : preferredSize = Size.fromHeight(kToolbarHeight), - super(key: key); + }) : super(key: key); @override _ImageFooterState createState() => _ImageFooterState(); - - @override - final Size preferredSize; } class _ImageFooterState extends State { @@ -150,7 +146,7 @@ class _ImageFooterState extends State { ); } - Widget _buildPhotosModal(context) { + void _buildPhotosModal(context) { var videoAttachments = widget.mediaAttachments .where((element) => element.type == 'video') .toList(); diff --git a/lib/src/media_list_view.dart b/lib/src/media_list_view.dart index 08ebfcc7..9c3af69f 100644 --- a/lib/src/media_list_view.dart +++ b/lib/src/media_list_view.dart @@ -37,13 +37,12 @@ class _MediaListViewState extends State { final _media = []; final ScrollController _scrollController = ScrollController(); int _currentPage = 0; - bool _endPagination = false; @override Widget build(BuildContext context) { return LazyLoadScrollView( - onEndOfPage: () { - _getMedia(); + onEndOfPage: () async { + return _getMedia(); }, child: GridView.builder( itemCount: _media.length, @@ -161,11 +160,7 @@ class _MediaListViewState extends State { final media = await assetList.getAssetListPaged(_currentPage, 50); - if (media.isEmpty) { - setState(() { - _endPagination = true; - }); - } else { + if (!media.isEmpty) { setState(() { _media.addAll(media); }); diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 5c175512..57e32c52 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -573,33 +573,6 @@ class _MessageWidgetState extends State { widget.message.attachments?.any((element) => element.type == 'giphy') == true; - Widget _buildReadIndicator() { - var padding = 0.0; - return Stack( - children: widget.readList.map((e) { - padding += 10.0; - return Positioned( - left: padding - 10, - bottom: 0, - top: 0, - child: Material( - color: StreamChatTheme.of(context).colorTheme.white, - clipBehavior: Clip.antiAlias, - shape: CircleBorder(), - child: Padding( - padding: const EdgeInsets.all(1.0), - child: UserAvatar( - user: e.user, - constraints: BoxConstraints.loose(Size.fromRadius(8)), - showOnlineStatus: false, - ), - ), - ), - ); - }).toList(), - ); - } - Widget _buildReactionIndicator( BuildContext context, ) { diff --git a/lib/src/stream_chat.dart b/lib/src/stream_chat.dart index 6866b0dd..521dc3c0 100644 --- a/lib/src/stream_chat.dart +++ b/lib/src/stream_chat.dart @@ -112,7 +112,6 @@ class StreamChatState extends State with WidgetsBindingObserver { inputBackground: themeData?.channelTheme?.inputBackground, messageInputButtonIconTheme: themeData?.channelTheme?.messageInputButtonIconTheme, - inputGradient: themeData?.channelTheme?.inputGradient, messageInputButtonTheme: themeData?.channelTheme?.messageInputButtonTheme, ), diff --git a/lib/src/stream_chat_theme.dart b/lib/src/stream_chat_theme.dart index ec469f81..02abd25c 100644 --- a/lib/src/stream_chat_theme.dart +++ b/lib/src/stream_chat_theme.dart @@ -92,12 +92,7 @@ class StreamChatThemeData { return defaultTheme.copyWith( primaryIconTheme: theme.primaryIconTheme, - channelTheme: defaultTheme.channelTheme.copyWith( - inputGradient: LinearGradient(colors: [ - theme.accentColor.withOpacity(.5), - theme.accentColor, - ]), - ), + channelTheme: defaultTheme.channelTheme, ownMessageTheme: defaultTheme.ownMessageTheme.copyWith( replies: defaultTheme.ownMessageTheme.replies.copyWith( color: theme.accentColor, @@ -168,8 +163,6 @@ class StreamChatThemeData { this.channelTheme.messageInputButtonIconTheme, messageInputButtonTheme: channelTheme.messageInputButtonTheme ?? this.channelTheme.messageInputButtonTheme, - inputGradient: - channelTheme.inputGradient ?? this.channelTheme.inputGradient, inputBackground: channelTheme.inputBackground ?? this.channelTheme.inputBackground, ) ?? @@ -273,10 +266,6 @@ class StreamChatThemeData { ), ), inputBackground: colorTheme.white.withAlpha(12), - inputGradient: LinearGradient(colors: [ - Color(0xFF00AEFF), - Color(0xFF0076FF), - ]), ), ownMessageTheme: MessageTheme( messageText: TextStyle( @@ -597,9 +586,6 @@ class ChannelTheme { /// Theme of the send button in [MessageInput] final ButtonThemeData messageInputButtonTheme; - /// Gradient of [MessageInput] - final Gradient inputGradient; - /// Background color of [MessageInput] final Color inputBackground; @@ -608,7 +594,6 @@ class ChannelTheme { this.messageInputButtonIconTheme, this.messageInputButtonTheme, this.inputBackground, - this.inputGradient, }); /// Creates a copy of [ChannelTheme] with specified attributes overridden. @@ -616,7 +601,6 @@ class ChannelTheme { ChannelHeaderTheme channelHeaderTheme, IconThemeData messageInputButtonIconTheme, ButtonThemeData messageInputButtonTheme, - Gradient inputGradient, Color inputBackground, }) => ChannelTheme( @@ -633,8 +617,6 @@ class ChannelTheme { messageInputButtonIconTheme ?? this.messageInputButtonIconTheme, messageInputButtonTheme: messageInputButtonTheme ?? this.messageInputButtonTheme, - inputGradient: inputGradient ?? this.inputGradient, - inputBackground: inputBackground ?? this.inputBackground, ); } From 041c1930c22c68d4a940c4fc1e4ddfe7d9ec679c Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 4 Jan 2021 12:08:14 +0100 Subject: [PATCH 4/4] fix longpress gesturedetector on message --- lib/src/message_widget.dart | 357 ++++++++++++++++++------------------ 1 file changed, 179 insertions(+), 178 deletions(-) diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 57e32c52..6ef537f6 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -260,174 +260,181 @@ class _MessageWidgetState extends State { true; return Portal( - child: Padding( - padding: widget.padding ?? EdgeInsets.all(8), - child: Transform( - alignment: Alignment.center, - transform: Matrix4.rotationY(widget.reverse ? pi : 0), - child: FractionallySizedBox( - alignment: Alignment.centerLeft, - widthFactor: 0.75, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Stack( - clipBehavior: Clip.none, - alignment: AlignmentDirectional.bottomStart, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - if (widget.showUserAvatar == DisplayWidget.show) - _buildUserAvatar(), - SizedBox(width: 6), - if (widget.showUserAvatar == DisplayWidget.hide) - SizedBox( - width: widget.messageTheme.avatarTheme - .constraints.maxWidth + - 8, - ), - Flexible( - child: PortalEntry( - portal: Container( - transform: - Matrix4.translationValues(-16, 2, 0), - child: _buildReactionIndicator(context), - constraints: - BoxConstraints(maxWidth: 22 * 6.0), + child: GestureDetector( + onLongPress: () => onLongPress(context), + child: Padding( + padding: widget.padding ?? EdgeInsets.all(8), + child: Transform( + alignment: Alignment.center, + transform: Matrix4.rotationY(widget.reverse ? pi : 0), + child: FractionallySizedBox( + alignment: Alignment.centerLeft, + widthFactor: 0.75, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Stack( + clipBehavior: Clip.none, + alignment: AlignmentDirectional.bottomStart, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + if (widget.showUserAvatar == DisplayWidget.show) + _buildUserAvatar(), + SizedBox(width: 6), + if (widget.showUserAvatar == DisplayWidget.hide) + SizedBox( + width: widget.messageTheme.avatarTheme + .constraints.maxWidth + + 8, ), - portalAnchor: Alignment(-1.0, -1.0), - childAnchor: Alignment(1, -1.0), - child: Stack( - clipBehavior: Clip.none, - children: [ - Padding( - padding: widget.showReactions - ? EdgeInsets.only( - top: widget.message.reactionCounts - ?.isNotEmpty == - true - ? 18 - : 0, - ) - : EdgeInsets.zero, - child: (widget.message.isDeleted && - !isFailedState) - ? Transform( - alignment: Alignment.center, - transform: Matrix4.rotationY( - widget.reverse ? pi : 0), - child: DeletedMessage( - reverse: widget.reverse, - borderRadiusGeometry: - widget.borderRadiusGeometry, - borderSide: widget.borderSide, - shape: widget.shape, - messageTheme: - widget.messageTheme, - ), - ) - : 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, + Flexible( + 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), + childAnchor: Alignment(1, -1.0), + child: Stack( + clipBehavior: Clip.none, + children: [ + Padding( + padding: widget.showReactions + ? EdgeInsets.only( + top: widget + .message + .reactionCounts + ?.isNotEmpty == + true + ? 18 + : 0, + ) + : EdgeInsets.zero, + child: (widget.message.isDeleted && + !isFailedState) + ? Transform( + alignment: Alignment.center, + transform: Matrix4.rotationY( + widget.reverse ? pi : 0), + child: DeletedMessage( + reverse: widget.reverse, + borderRadiusGeometry: widget + .borderRadiusGeometry, + borderSide: widget.borderSide, + shape: widget.shape, + messageTheme: + widget.messageTheme, + ), + ) + : 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: Padding( + padding: EdgeInsets.all( + hasFiles ? 2.0 : 0.0), + child: Column( + crossAxisAlignment: + CrossAxisAlignment + .start, + mainAxisSize: + MainAxisSize.min, + children: [ + ..._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: [ - ..._parseAttachments( - context), - if (widget.message.text - .trim() - .isNotEmpty && - !isGiphy) - _buildTextBubble(context), - ], ), ), - ), - ), - if (widget.showReactionPickerIndicator) - Positioned( - right: 0, - top: -6, - child: Transform( - transform: Matrix4.rotationY( - widget.reverse ? pi : 0), - child: CustomPaint( - painter: ReactionBubblePainter( - widget.messageTheme - .reactionsBackgroundColor, - widget.messageTheme - .reactionsBorderColor, + ), + if (widget.showReactionPickerIndicator) + Positioned( + right: 0, + top: -6, + child: Transform( + transform: Matrix4.rotationY( + widget.reverse ? pi : 0), + child: CustomPaint( + painter: ReactionBubblePainter( + widget.messageTheme + .reactionsBackgroundColor, + widget.messageTheme + .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 { }) { final attachmentShape = widget.attachmentShape ?? widget.shape ?? _getDefaultShape(context); - return GestureDetector( - onLongPress: () => onLongPress(context), - child: Material( - color: _getBackgroundColor(), - clipBehavior: Clip.antiAlias, - shape: attachmentShape, - child: Padding( - padding: widget.attachmentPadding, - child: Material( - clipBehavior: Clip.hardEdge, - shape: attachmentShape, - type: MaterialType.transparency, - child: Transform( - transform: Matrix4.rotationY(widget.reverse ? pi : 0), - alignment: Alignment.center, - child: attachmentWidget, - ), + return Material( + color: _getBackgroundColor(), + clipBehavior: Clip.antiAlias, + shape: attachmentShape, + child: Padding( + padding: widget.attachmentPadding, + child: Material( + clipBehavior: Clip.hardEdge, + shape: attachmentShape, + type: MaterialType.transparency, + child: Transform( + transform: Matrix4.rotationY(widget.reverse ? pi : 0), + alignment: Alignment.center, + child: attachmentWidget, ), ), ), @@ -854,10 +858,7 @@ class _MessageWidgetState extends State { ], ), ); - return GestureDetector( - onLongPress: () => onLongPress(context), - child: child, - ); + return child; } bool get isOnlyEmoji =>