From c0951272ebbd906750ccc9e774a8f660da657814 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 26 Jul 2021 15:06:47 +0530 Subject: [PATCH] feat: Extracted visible_footnote.dart, corrected default filter --- .../lib/src/attachment/giphy_attachment.dart | 32 +++---------------- .../lib/src/message_widget.dart | 28 +++++++--------- .../lib/src/visible_footnote.dart | 29 +++++++++++++++++ .../lib/src/message_list_core.dart | 3 +- 4 files changed, 45 insertions(+), 47 deletions(-) create mode 100644 packages/stream_chat_flutter/lib/src/visible_footnote.dart diff --git a/packages/stream_chat_flutter/lib/src/attachment/giphy_attachment.dart b/packages/stream_chat_flutter/lib/src/attachment/giphy_attachment.dart index f14abffc..fd29724d 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/giphy_attachment.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/giphy_attachment.dart @@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:shimmer/shimmer.dart'; import 'package:stream_chat_flutter/src/attachment/attachment_widget.dart'; +import 'package:stream_chat_flutter/src/visible_footnote.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; @@ -216,36 +217,11 @@ class GiphyAttachment extends AttachmentWidget { ), ), const SizedBox(height: 4), - Align( + const Align( alignment: Alignment.centerRight, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - StreamSvgIcon.eye( - color: StreamChatTheme.of(context) - .colorTheme - .textHighEmphasis - .withOpacity(0.5), - size: 16, - ), - const SizedBox( - width: 8, - ), - Text( - 'Only visible to you', - style: StreamChatTheme.of(context) - .textTheme - .footnote - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .textHighEmphasis - .withOpacity(0.5)), - ), - ], - ), + padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: VisibleFootnote(), ), ), ], diff --git a/packages/stream_chat_flutter/lib/src/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget.dart index c9dfd9d4..47f1182b 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget.dart @@ -15,6 +15,7 @@ import 'package:stream_chat_flutter/src/message_reactions_modal.dart'; import 'package:stream_chat_flutter/src/quoted_message_widget.dart'; import 'package:stream_chat_flutter/src/reaction_bubble.dart'; import 'package:stream_chat_flutter/src/url_attachment.dart'; +import 'package:stream_chat_flutter/src/visible_footnote.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; /// Widget builder for building attachments @@ -92,6 +93,7 @@ class MessageWidget extends StatefulWidget { this.userAvatarBuilder, this.editMessageInputBuilder, this.textBuilder, + this.bottomRowBuilder, this.onReturnAction, Map? customAttachmentBuilders, this.readList, @@ -275,6 +277,9 @@ class MessageWidget extends StatefulWidget { /// Function called on long press final void Function(BuildContext, Message)? onMessageActions; + /// Widget builder for building a bottom row below the message + final Widget Function(BuildContext, Message)? bottomRowBuilder; + /// Widget builder for building user avatar final Widget Function(BuildContext, User)? userAvatarBuilder; @@ -782,7 +787,11 @@ class _MessageWidgetState extends State bottom: isPinned && widget.showPinHighlight ? 6.0 : 0.0, ), - child: _bottomRow, + child: widget.bottomRowBuilder?.call( + context, + widget.message, + ) ?? + _bottomRow, ), if (isFailedState) Positioned( @@ -830,22 +839,7 @@ class _MessageWidgetState extends State Widget get _bottomRow { if (isDeleted) { - final chatThemeData = _streamChatTheme; - return Row( - mainAxisSize: MainAxisSize.min, - children: [ - StreamSvgIcon.eye( - color: chatThemeData.colorTheme.textLowEmphasis, - size: 16, - ), - const SizedBox(width: 8), - Text( - 'Only visible to you', - style: chatThemeData.textTheme.footnote - .copyWith(color: chatThemeData.colorTheme.textLowEmphasis), - ), - ], - ); + return const VisibleFootnote(); } final children = []; diff --git a/packages/stream_chat_flutter/lib/src/visible_footnote.dart b/packages/stream_chat_flutter/lib/src/visible_footnote.dart new file mode 100644 index 00000000..bbdb9144 --- /dev/null +++ b/packages/stream_chat_flutter/lib/src/visible_footnote.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import 'package:stream_chat_flutter/src/stream_chat_theme.dart'; +import 'package:stream_chat_flutter/stream_chat_flutter.dart'; + +/// Widget for displaying a footnote +class VisibleFootnote extends StatelessWidget { + /// Constructor for creating a [VisibleFootnote] + const VisibleFootnote({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final chatThemeData = StreamChatTheme.of(context); + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + StreamSvgIcon.eye( + color: chatThemeData.colorTheme.textLowEmphasis, + size: 16, + ), + const SizedBox(width: 8), + Text( + 'Only visible to you', + style: chatThemeData.textTheme.footnote + .copyWith(color: chatThemeData.colorTheme.textLowEmphasis), + ), + ], + ); + } +} diff --git a/packages/stream_chat_flutter_core/lib/src/message_list_core.dart b/packages/stream_chat_flutter_core/lib/src/message_list_core.dart index 4acf0ba7..83ef4e24 100644 --- a/packages/stream_chat_flutter_core/lib/src/message_list_core.dart +++ b/packages/stream_chat_flutter_core/lib/src/message_list_core.dart @@ -134,8 +134,7 @@ class MessageListCoreState extends State { bool defaultFilter(Message m) { final isMyMessage = m.user?.id == _currentUser?.id; - final isDeletedOrShadowed = m.isDeleted == true || m.shadowed == true; - if (isDeletedOrShadowed && !isMyMessage) return false; + if (m.shadowed && !isMyMessage) return false; return true; }