From 02c824d205e3e1072072c1618e11128adbdfefae Mon Sep 17 00:00:00 2001 From: Vatsal Tanna Date: Thu, 27 Jun 2024 18:12:05 +0530 Subject: [PATCH] refactor: :hammer: updated config dependencies using inherited widget and remove unnecessary repetitive code --- lib/src/extensions/extensions.dart | 21 +- .../configurations_inherited_widgets.dart | 59 +++++ lib/src/widgets/chat_bubble_widget.dart | 241 +++++++----------- lib/src/widgets/chat_groupedlist_widget.dart | 124 +++------ lib/src/widgets/chat_list_widget.dart | 64 +---- lib/src/widgets/chat_view.dart | 150 +++++------ lib/src/widgets/emoji_row.dart | 22 +- lib/src/widgets/message_time_widget.dart | 19 +- lib/src/widgets/reaction_popup.dart | 43 +--- lib/src/widgets/reaction_widget.dart | 4 +- lib/src/widgets/send_message_widget.dart | 17 +- .../widgets/suggestions/suggestion_item.dart | 2 +- .../widgets/suggestions/suggestion_list.dart | 12 +- lib/src/widgets/type_indicator_widget.dart | 4 +- 14 files changed, 333 insertions(+), 449 deletions(-) create mode 100644 lib/src/inherited_widgets/configurations_inherited_widgets.dart diff --git a/lib/src/extensions/extensions.dart b/lib/src/extensions/extensions.dart index aa5000c4..cbc0eec3 100644 --- a/lib/src/extensions/extensions.dart +++ b/lib/src/extensions/extensions.dart @@ -20,6 +20,7 @@ * SOFTWARE. */ import 'package:chatview/chatview.dart'; +import 'package:chatview/src/inherited_widgets/configurations_inherited_widgets.dart'; import 'package:chatview/src/widgets/chat_view_inherited_widget.dart'; import 'package:chatview/src/widgets/profile_image_widget.dart'; import 'package:chatview/src/widgets/suggestions/suggestions_config_inherited_widget.dart'; @@ -129,18 +130,34 @@ extension ChatViewStateTitleExtension on String? { /// Extension on State for accessing inherited widget. extension StatefulWidgetExtension on State { - ChatViewInheritedWidget? get provide => + ChatViewInheritedWidget? get chatViewIW => mounted ? ChatViewInheritedWidget.of(context) : null; ReplySuggestionsConfig? get suggestionsConfig => mounted ? SuggestionsConfigIW.of(context)?.suggestionsConfig : null; + + ConfigurationsInheritedWidget get chatListConfig => + mounted && ConfigurationsInheritedWidget.of(context) != null + ? ConfigurationsInheritedWidget.of(context)! + : const ConfigurationsInheritedWidget( + chatBackgroundConfig: ChatBackgroundConfiguration(), + child: SizedBox.shrink(), + ); } /// Extension on State for accessing inherited widget. extension BuildContextExtension on BuildContext { - ChatViewInheritedWidget? get provide => + ChatViewInheritedWidget? get chatViewIW => mounted ? ChatViewInheritedWidget.of(this) : null; ReplySuggestionsConfig? get suggestionsConfig => mounted ? SuggestionsConfigIW.of(this)?.suggestionsConfig : null; + + ConfigurationsInheritedWidget get chatListConfig => + mounted && ConfigurationsInheritedWidget.of(this) != null + ? ConfigurationsInheritedWidget.of(this)! + : const ConfigurationsInheritedWidget( + chatBackgroundConfig: ChatBackgroundConfiguration(), + child: SizedBox.shrink(), + ); } diff --git a/lib/src/inherited_widgets/configurations_inherited_widgets.dart b/lib/src/inherited_widgets/configurations_inherited_widgets.dart new file mode 100644 index 00000000..61470d3d --- /dev/null +++ b/lib/src/inherited_widgets/configurations_inherited_widgets.dart @@ -0,0 +1,59 @@ +import 'package:chatview/src/models/models.dart'; +import 'package:emoji_picker_flutter/emoji_picker_flutter.dart'; +import 'package:flutter/material.dart'; + +class ConfigurationsInheritedWidget extends InheritedWidget { + const ConfigurationsInheritedWidget({ + Key? key, + required Widget child, + required this.chatBackgroundConfig, + this.reactionPopupConfig, + this.messageConfig, + this.chatBubbleConfig, + this.profileCircleConfig, + this.swipeToReplyConfig, + this.repliedMessageConfig, + this.typeIndicatorConfig, + this.replyPopupConfig, + this.emojiPickerSheetConfig, + }) : super(key: key, child: child); + + /// Provides configuration for background of chat. + final ChatBackgroundConfiguration chatBackgroundConfig; + + /// Provides configuration for reaction pop up appearance. + final ReactionPopupConfiguration? reactionPopupConfig; + + /// Provides configuration for customisation of different types + /// messages. + final MessageConfiguration? messageConfig; + + /// Provides configuration of chat bubble's appearance. + final ChatBubbleConfiguration? chatBubbleConfig; + + /// Provides configuration for profile circle avatar of user. + final ProfileCircleConfiguration? profileCircleConfig; + + /// Provides configuration for when user swipe to chat bubble. + final SwipeToReplyConfiguration? swipeToReplyConfig; + + /// Provides configuration for replied message view which is located upon chat + /// bubble. + final RepliedMessageConfiguration? repliedMessageConfig; + + /// Provides configuration of typing indicator's appearance. + final TypeIndicatorConfiguration? typeIndicatorConfig; + + /// Provides configuration for reply snack bar's appearance and options. + final ReplyPopupConfiguration? replyPopupConfig; + + /// Configuration for emoji picker sheet + final Config? emojiPickerSheetConfig; + + static ConfigurationsInheritedWidget? of(BuildContext context) => context + .dependOnInheritedWidgetOfExactType(); + + @override + bool updateShouldNotify(covariant ConfigurationsInheritedWidget oldWidget) => + oldWidget != this; +} diff --git a/lib/src/widgets/chat_bubble_widget.dart b/lib/src/widgets/chat_bubble_widget.dart index 4264e55c..0cfa90a2 100644 --- a/lib/src/widgets/chat_bubble_widget.dart +++ b/lib/src/widgets/chat_bubble_widget.dart @@ -38,13 +38,6 @@ class ChatBubbleWidget extends StatefulWidget { required this.onLongPress, required this.slideAnimation, required this.onSwipe, - this.profileCircleConfig, - this.chatBubbleConfig, - this.repliedMessageConfig, - this.swipeToReplyConfig, - this.messageTimeTextStyle, - this.messageTimeIconColor, - this.messageConfig, this.onReplyTap, this.shouldHighlight = false, }) : super(key: key); @@ -55,37 +48,12 @@ class ChatBubbleWidget extends StatefulWidget { /// Give callback once user long press on chat bubble. final DoubleCallBack onLongPress; - /// Provides configuration related to user profile circle avatar. - final ProfileCircleConfiguration? profileCircleConfig; - - /// Provides configurations related to chat bubble such as padding, margin, max - /// width etc. - final ChatBubbleConfiguration? chatBubbleConfig; - - /// Provides configurations related to replied message such as textstyle - /// padding, margin etc. Also, this widget is located upon chat bubble. - final RepliedMessageConfiguration? repliedMessageConfig; - - /// Provides configurations related to swipe chat bubble which triggers - /// when user swipe chat bubble. - final SwipeToReplyConfiguration? swipeToReplyConfig; - - /// Provides textStyle of message created time when user swipe whole chat. - final TextStyle? messageTimeTextStyle; - - /// Provides default icon color of message created time view when user swipe - /// whole chat. - final Color? messageTimeIconColor; + /// Provides callback of when user swipe chat bubble for reply. + final MessageCallBack onSwipe; /// Provides slide animation when user swipe whole chat. final Animation? slideAnimation; - /// Provides configuration of all types of messages. - final MessageConfiguration? messageConfig; - - /// Provides callback of when user swipe chat bubble for reply. - final MessageCallBack onSwipe; - /// Provides callback when user tap on replied message upon chat bubble. final Function(String)? onReplyTap; @@ -104,8 +72,6 @@ class _ChatBubbleWidgetState extends State { bool get isLastMessage => chatController?.initialMessageList.last.id == widget.message.id; - ProfileCircleConfiguration? get profileCircleConfig => - widget.profileCircleConfig; FeatureActiveConfig? featureActiveConfig; ChatController? chatController; ChatUser? currentUser; @@ -114,9 +80,9 @@ class _ChatBubbleWidgetState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - featureActiveConfig = provide!.featureActiveConfig; - chatController = provide!.chatController; + if (chatViewIW != null) { + featureActiveConfig = chatViewIW!.featureActiveConfig; + chatController = chatViewIW!.chatController; currentUser = chatController?.currentUser; } } @@ -136,8 +102,6 @@ class _ChatBubbleWidgetState extends State { child: MessageTimeWidget( messageTime: widget.message.createdAt, isCurrentUser: isMessageBySender, - messageTimeIconColor: widget.messageTimeIconColor, - messageTimeTextStyle: widget.messageTimeTextStyle, ), ), ), @@ -153,11 +117,10 @@ class _ChatBubbleWidgetState extends State { } Widget _chatBubbleWidget(ChatUser? messagedUser) { + final chatBubbleConfig = chatListConfig.chatBubbleConfig; return Container( - padding: - widget.chatBubbleConfig?.padding ?? const EdgeInsets.only(left: 5.0), - margin: - widget.chatBubbleConfig?.margin ?? const EdgeInsets.only(bottom: 10), + padding: chatBubbleConfig?.padding ?? const EdgeInsets.only(left: 5.0), + margin: chatBubbleConfig?.margin ?? const EdgeInsets.only(bottom: 10), child: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: @@ -166,103 +129,83 @@ class _ChatBubbleWidgetState extends State { children: [ if (!isMessageBySender && (featureActiveConfig?.enableOtherUserProfileAvatar ?? true)) - ProfileCircle( - bottomPadding: widget.message.reaction.reactions.isNotEmpty - ? profileCircleConfig?.bottomPadding ?? 15 - : profileCircleConfig?.bottomPadding ?? 2, - profileCirclePadding: profileCircleConfig?.padding, - imageUrl: messagedUser?.profilePhoto, - imageType: messagedUser?.imageType, - defaultAvatarImage: - messagedUser?.defaultAvatarImage ?? profileImage, - networkImageProgressIndicatorBuilder: - messagedUser?.networkImageProgressIndicatorBuilder, - assetImageErrorBuilder: messagedUser?.assetImageErrorBuilder, - networkImageErrorBuilder: messagedUser?.networkImageErrorBuilder, - circleRadius: profileCircleConfig?.circleRadius, - onTap: () => _onAvatarTap(messagedUser), - onLongPress: () => _onAvatarLongPress(messagedUser), - ), + profileCircle(messagedUser), Expanded( - child: isMessageBySender - ? SwipeToReply( - onLeftSwipe: featureActiveConfig?.enableSwipeToReply ?? true - ? () { - if (maxDuration != null) { - widget.message.voiceMessageDuration = - Duration(milliseconds: maxDuration!); - } - if (widget.swipeToReplyConfig?.onLeftSwipe != - null) { - widget.swipeToReplyConfig?.onLeftSwipe!( - widget.message.message, - widget.message.sentBy); - } - widget.onSwipe(widget.message); - } - : null, - replyIconColor: widget.swipeToReplyConfig?.replyIconColor, - swipeToReplyAnimationDuration: - widget.swipeToReplyConfig?.animationDuration, - child: _messagesWidgetColumn(messagedUser), - ) - : SwipeToReply( - onRightSwipe: - featureActiveConfig?.enableSwipeToReply ?? true - ? () { - if (maxDuration != null) { - widget.message.voiceMessageDuration = - Duration(milliseconds: maxDuration!); - } - if (widget.swipeToReplyConfig?.onRightSwipe != - null) { - widget.swipeToReplyConfig?.onRightSwipe!( - widget.message.message, - widget.message.sentBy); - } - widget.onSwipe(widget.message); - } - : null, - replyIconColor: widget.swipeToReplyConfig?.replyIconColor, - swipeToReplyAnimationDuration: - widget.swipeToReplyConfig?.animationDuration, - child: _messagesWidgetColumn(messagedUser), - ), + child: SwipeToReply( + onLeftSwipe: featureActiveConfig?.enableSwipeToReply ?? true + ? isMessageBySender + ? onLeftSwipe + : onRightSwipe + : null, + replyIconColor: chatListConfig.swipeToReplyConfig?.replyIconColor, + swipeToReplyAnimationDuration: + chatListConfig.swipeToReplyConfig?.animationDuration, + child: _messagesWidgetColumn(messagedUser), + ), ), - if (isMessageBySender) ...[getReciept()], + if (isMessageBySender) ...[getReceipt()], if (isMessageBySender && (featureActiveConfig?.enableCurrentUserProfileAvatar ?? true)) - ProfileCircle( - bottomPadding: widget.message.reaction.reactions.isNotEmpty - ? profileCircleConfig?.bottomPadding ?? 15 - : profileCircleConfig?.bottomPadding ?? 2, - profileCirclePadding: profileCircleConfig?.padding, - imageUrl: currentUser?.profilePhoto, - imageType: currentUser?.imageType, - defaultAvatarImage: - currentUser?.defaultAvatarImage ?? profileImage, - networkImageProgressIndicatorBuilder: - currentUser?.networkImageProgressIndicatorBuilder, - networkImageErrorBuilder: currentUser?.networkImageErrorBuilder, - assetImageErrorBuilder: currentUser?.assetImageErrorBuilder, - circleRadius: profileCircleConfig?.circleRadius, - onTap: () => _onAvatarTap(messagedUser), - onLongPress: () => _onAvatarLongPress(messagedUser), - ), + profileCircle(messagedUser), ], ), ); } + ProfileCircle profileCircle(ChatUser? messagedUser) { + final profileCircleConfig = chatListConfig.profileCircleConfig; + return ProfileCircle( + bottomPadding: widget.message.reaction.reactions.isNotEmpty + ? profileCircleConfig?.bottomPadding ?? 15 + : profileCircleConfig?.bottomPadding ?? 2, + profileCirclePadding: profileCircleConfig?.padding, + imageUrl: messagedUser?.profilePhoto, + imageType: messagedUser?.imageType, + defaultAvatarImage: messagedUser?.defaultAvatarImage ?? profileImage, + networkImageProgressIndicatorBuilder: + messagedUser?.networkImageProgressIndicatorBuilder, + assetImageErrorBuilder: messagedUser?.assetImageErrorBuilder, + networkImageErrorBuilder: messagedUser?.networkImageErrorBuilder, + circleRadius: profileCircleConfig?.circleRadius, + onTap: () => _onAvatarTap(messagedUser), + onLongPress: () => _onAvatarLongPress(messagedUser), + ); + } + + void onRightSwipe() { + if (maxDuration != null) { + widget.message.voiceMessageDuration = + Duration(milliseconds: maxDuration!); + } + if (chatListConfig.swipeToReplyConfig?.onRightSwipe != null) { + chatListConfig.swipeToReplyConfig?.onRightSwipe!( + widget.message.message, widget.message.sentBy); + } + widget.onSwipe(widget.message); + } + + void onLeftSwipe() { + if (maxDuration != null) { + widget.message.voiceMessageDuration = + Duration(milliseconds: maxDuration!); + } + if (chatListConfig.swipeToReplyConfig?.onLeftSwipe != null) { + chatListConfig.swipeToReplyConfig?.onLeftSwipe!( + widget.message.message, widget.message.sentBy); + } + widget.onSwipe(widget.message); + } + void _onAvatarTap(ChatUser? user) { - if (profileCircleConfig?.onAvatarTap != null && user != null) { - profileCircleConfig?.onAvatarTap!(user); + if (chatListConfig.profileCircleConfig?.onAvatarTap != null && + user != null) { + chatListConfig.profileCircleConfig?.onAvatarTap!(user); } } - Widget getReciept() { - final showReceipts = widget.chatBubbleConfig?.outgoingChatBubbleConfig - ?.receiptsWidgetConfig?.showReceiptsIn ?? + Widget getReceipt() { + final showReceipts = chatListConfig.chatBubbleConfig + ?.outgoingChatBubbleConfig?.receiptsWidgetConfig?.showReceiptsIn ?? ShowReceiptsIn.lastMessage; if (showReceipts == ShowReceiptsIn.all) { return ValueListenableBuilder( @@ -272,7 +215,7 @@ class _ChatBubbleWidgetState extends State { ?.featureActiveConfig .receiptsBuilderVisibility ?? true) { - return widget.chatBubbleConfig?.outgoingChatBubbleConfig + return chatListConfig.chatBubbleConfig?.outgoingChatBubbleConfig ?.receiptsWidgetConfig?.receiptsBuilder ?.call(value) ?? sendMessageAnimationBuilder(value); @@ -289,7 +232,7 @@ class _ChatBubbleWidgetState extends State { ?.featureActiveConfig .receiptsBuilderVisibility ?? true) { - return widget.chatBubbleConfig?.outgoingChatBubbleConfig + return chatListConfig.chatBubbleConfig?.outgoingChatBubbleConfig ?.receiptsWidgetConfig?.receiptsBuilder ?.call(value) ?? sendMessageAnimationBuilder(value); @@ -301,8 +244,9 @@ class _ChatBubbleWidgetState extends State { } void _onAvatarLongPress(ChatUser? user) { - if (profileCircleConfig?.onAvatarLongPress != null && user != null) { - profileCircleConfig?.onAvatarLongPress!(user); + if (chatListConfig.profileCircleConfig?.onAvatarLongPress != null && + user != null) { + chatListConfig.profileCircleConfig?.onAvatarLongPress!(user); } } @@ -315,42 +259,43 @@ class _ChatBubbleWidgetState extends State { !isMessageBySender && (featureActiveConfig?.enableOtherUserName ?? true)) Padding( - padding: - widget.chatBubbleConfig?.inComingChatBubbleConfig?.padding ?? - const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: chatListConfig + .chatBubbleConfig?.inComingChatBubbleConfig?.padding ?? + const EdgeInsets.symmetric(horizontal: 8, vertical: 4), child: Text( messagedUser?.name ?? '', - style: widget.chatBubbleConfig?.inComingChatBubbleConfig + style: chatListConfig.chatBubbleConfig?.inComingChatBubbleConfig ?.senderNameTextStyle, ), ), if (replyMessage.isNotEmpty) - widget.repliedMessageConfig?.repliedMessageWidgetBuilder != null - ? widget.repliedMessageConfig! + chatListConfig.repliedMessageConfig?.repliedMessageWidgetBuilder != + null + ? chatListConfig.repliedMessageConfig! .repliedMessageWidgetBuilder!(widget.message.replyMessage) : ReplyMessageWidget( message: widget.message, - repliedMessageConfig: widget.repliedMessageConfig, + repliedMessageConfig: chatListConfig.repliedMessageConfig, onTap: () => widget.onReplyTap ?.call(widget.message.replyMessage.messageId), ), MessageView( outgoingChatBubbleConfig: - widget.chatBubbleConfig?.outgoingChatBubbleConfig, + chatListConfig.chatBubbleConfig?.outgoingChatBubbleConfig, isLongPressEnable: (featureActiveConfig?.enableReactionPopup ?? true) || (featureActiveConfig?.enableReplySnackBar ?? true), inComingChatBubbleConfig: - widget.chatBubbleConfig?.inComingChatBubbleConfig, + chatListConfig.chatBubbleConfig?.inComingChatBubbleConfig, message: widget.message, isMessageBySender: isMessageBySender, - messageConfig: widget.messageConfig, + messageConfig: chatListConfig.messageConfig, onLongPress: widget.onLongPress, - chatBubbleMaxWidth: widget.chatBubbleConfig?.maxWidth, + chatBubbleMaxWidth: chatListConfig.chatBubbleConfig?.maxWidth, longPressAnimationDuration: - widget.chatBubbleConfig?.longPressAnimationDuration, + chatListConfig.chatBubbleConfig?.longPressAnimationDuration, onDoubleTap: featureActiveConfig?.enableDoubleTapToLike ?? false - ? widget.chatBubbleConfig?.onDoubleTap ?? + ? chatListConfig.chatBubbleConfig?.onDoubleTap ?? (message) => currentUser != null ? chatController?.setReaction( emoji: heart, @@ -361,10 +306,10 @@ class _ChatBubbleWidgetState extends State { : null, shouldHighlight: widget.shouldHighlight, controller: chatController, - highlightColor: widget.repliedMessageConfig + highlightColor: chatListConfig.repliedMessageConfig ?.repliedMsgAutoScrollConfig.highlightColor ?? Colors.grey, - highlightScale: widget.repliedMessageConfig + highlightScale: chatListConfig.repliedMessageConfig ?.repliedMsgAutoScrollConfig.highlightScale ?? 1.1, onMaxDuration: _onMaxDuration, diff --git a/lib/src/widgets/chat_groupedlist_widget.dart b/lib/src/widgets/chat_groupedlist_widget.dart index fc528ea3..9ba60f78 100644 --- a/lib/src/widgets/chat_groupedlist_widget.dart +++ b/lib/src/widgets/chat_groupedlist_widget.dart @@ -33,18 +33,11 @@ class ChatGroupedListWidget extends StatefulWidget { Key? key, required this.showPopUp, required this.scrollController, - required this.chatBackgroundConfig, required this.replyMessage, required this.assignReplyMessage, required this.onChatListTap, required this.onChatBubbleLongPress, required this.isEnableSwipeToSeeTime, - this.messageConfig, - this.chatBubbleConfig, - this.profileCircleConfig, - this.swipeToReplyConfig, - this.repliedMessageConfig, - this.typeIndicatorConfig, }) : super(key: key); /// Allow user to swipe to see time while reaction pop is not open. @@ -53,26 +46,6 @@ class ChatGroupedListWidget extends StatefulWidget { /// Pass scroll controller final ScrollController scrollController; - /// Allow user to give customisation to background of chat - final ChatBackgroundConfiguration chatBackgroundConfig; - - /// Allow user to giving customisation different types - /// messages - final MessageConfiguration? messageConfig; - - /// Allow user to giving customisation to chat bubble - final ChatBubbleConfiguration? chatBubbleConfig; - - /// Allow user to giving customisation to profile circle - final ProfileCircleConfiguration? profileCircleConfig; - - /// Allow user to giving customisation to swipe to reply - final SwipeToReplyConfiguration? swipeToReplyConfig; - final RepliedMessageConfiguration? repliedMessageConfig; - - /// Allow user to giving customisation typing indicator - final TypeIndicatorConfiguration? typeIndicatorConfig; - /// Provides reply message if actual message is sent by replying any message. final ReplyMessage replyMessage; @@ -95,18 +68,11 @@ class ChatGroupedListWidget extends StatefulWidget { class _ChatGroupedListWidgetState extends State with TickerProviderStateMixin { - ChatBackgroundConfiguration get chatBackgroundConfig => - widget.chatBackgroundConfig; - bool get showPopUp => widget.showPopUp; bool highlightMessage = false; final ValueNotifier _replyId = ValueNotifier(null); - ChatBubbleConfiguration? get chatBubbleConfig => widget.chatBubbleConfig; - - ProfileCircleConfiguration? get profileCircleConfig => - widget.profileCircleConfig; AnimationController? _animationController; Animation? _slideAnimation; @@ -116,6 +82,9 @@ class _ChatGroupedListWidgetState extends State bool get isEnableSwipeToSeeTime => widget.isEnableSwipeToSeeTime; + ChatBackgroundConfiguration get chatBackgroundConfig => + chatListConfig.chatBackgroundConfig; + double chatTextFieldHeight = 0; @override @@ -136,7 +105,7 @@ class _ChatGroupedListWidgetState extends State if (!mounted) return; setState(() { chatTextFieldHeight = - provide?.chatTextFieldViewKey.currentContext?.size?.height ?? 10; + chatViewIW?.chatTextFieldViewKey.currentContext?.size?.height ?? 10; }); }); } @@ -164,9 +133,9 @@ class _ChatGroupedListWidgetState extends State @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - featureActiveConfig = provide!.featureActiveConfig; - chatController = provide!.chatController; + if (chatViewIW != null) { + featureActiveConfig = chatViewIW!.featureActiveConfig; + chatController = chatViewIW!.chatController; } _initializeAnimation(); } @@ -184,16 +153,14 @@ class _ChatGroupedListWidgetState extends State mainAxisSize: MainAxisSize.min, children: [ GestureDetector( - onHorizontalDragUpdate: (details) => isEnableSwipeToSeeTime - ? showPopUp - ? null - : _onHorizontalDrag(details) - : null, - onHorizontalDragEnd: (details) => isEnableSwipeToSeeTime - ? showPopUp - ? null - : _animationController?.reverse() - : null, + onHorizontalDragUpdate: (details) => + isEnableSwipeToSeeTime && !showPopUp + ? _onHorizontalDrag(details) + : null, + onHorizontalDragEnd: (details) => + isEnableSwipeToSeeTime && !showPopUp + ? _animationController?.reverse() + : null, onTap: widget.onChatListTap, child: _animationController != null ? AnimatedBuilder( @@ -208,8 +175,9 @@ class _ChatGroupedListWidgetState extends State ValueListenableBuilder( valueListenable: chatController!.typingIndicatorNotifier, builder: (context, value, child) => TypingIndicator( - typeIndicatorConfig: widget.typeIndicatorConfig, - chatBubbleConfig: chatBubbleConfig?.inComingChatBubbleConfig, + typeIndicatorConfig: chatListConfig.typeIndicatorConfig, + chatBubbleConfig: + chatListConfig.chatBubbleConfig?.inComingChatBubbleConfig, showIndicator: value, ), ), @@ -234,33 +202,26 @@ class _ChatGroupedListWidgetState extends State Future _onReplyTap(String id, List? messages) async { // Finds the replied message if exists final repliedMessages = messages?.firstWhere((message) => id == message.id); - + final repliedMsgAutoScrollConfig = + chatListConfig.repliedMessageConfig?.repliedMsgAutoScrollConfig; + final highlightDuration = repliedMsgAutoScrollConfig?.highlightDuration ?? + const Duration(milliseconds: 300); // Scrolls to replied message and highlights if (repliedMessages != null && repliedMessages.key.currentState != null) { await Scrollable.ensureVisible( repliedMessages.key.currentState!.context, // This value will make widget to be in center when auto scrolled. alignment: 0.5, - curve: widget.repliedMessageConfig?.repliedMsgAutoScrollConfig - .highlightScrollCurve ?? - Curves.easeIn, - duration: widget.repliedMessageConfig?.repliedMsgAutoScrollConfig - .highlightDuration ?? - const Duration(milliseconds: 300), + curve: + repliedMsgAutoScrollConfig?.highlightScrollCurve ?? Curves.easeIn, + duration: highlightDuration, ); - if (widget.repliedMessageConfig?.repliedMsgAutoScrollConfig - .enableHighlightRepliedMsg ?? - false) { + if (repliedMsgAutoScrollConfig?.enableHighlightRepliedMsg ?? false) { _replyId.value = id; - Future.delayed( - widget.repliedMessageConfig?.repliedMsgAutoScrollConfig - .highlightDuration ?? - const Duration(milliseconds: 300), - () { - _replyId.value = null; - }, - ); + Future.delayed(highlightDuration, () { + _replyId.value = null; + }); } } } @@ -300,7 +261,7 @@ class _ChatGroupedListWidgetState extends State const CircularProgressIndicator(), ); } else { - final messages = widget.chatBackgroundConfig.sortEnable + final messages = chatBackgroundConfig.sortEnable ? sortMessage(snapshot.data!) : snapshot.data!; @@ -348,18 +309,14 @@ class _ChatGroupedListWidgetState extends State valueListenable: _replyId, builder: (context, state, child) { final message = messages[newIndex]; + final enableScrollToRepliedMsg = chatListConfig + .repliedMessageConfig + ?.repliedMsgAutoScrollConfig + .enableScrollToRepliedMsg ?? + false; return ChatBubbleWidget( key: message.key, - messageTimeTextStyle: - chatBackgroundConfig.messageTimeTextStyle, - messageTimeIconColor: - chatBackgroundConfig.messageTimeIconColor, message: message, - messageConfig: widget.messageConfig, - chatBubbleConfig: chatBubbleConfig, - profileCircleConfig: profileCircleConfig, - swipeToReplyConfig: widget.swipeToReplyConfig, - repliedMessageConfig: widget.repliedMessageConfig, slideAnimation: _slideAnimation, onLongPress: (yCoordinate, xCoordinate) => widget.onChatBubbleLongPress( @@ -369,11 +326,7 @@ class _ChatGroupedListWidgetState extends State ), onSwipe: widget.assignReplyMessage, shouldHighlight: state == message.id, - onReplyTap: widget - .repliedMessageConfig - ?.repliedMsgAutoScrollConfig - .enableScrollToRepliedMsg ?? - false + onReplyTap: enableScrollToRepliedMsg ? (replyId) => _onReplyTap(replyId, snapshot.data) : null, ); @@ -388,12 +341,11 @@ class _ChatGroupedListWidgetState extends State List sortMessage(List messages) { final elements = [...messages]; - elements.sort( - widget.chatBackgroundConfig.messageSorter ?? + chatBackgroundConfig.messageSorter ?? (a, b) => a.createdAt.compareTo(b.createdAt), ); - if (widget.chatBackgroundConfig.groupedListOrder.isAsc) { + if (chatBackgroundConfig.groupedListOrder.isAsc) { return elements.toList(); } else { return elements.reversed.toList(); diff --git a/lib/src/widgets/chat_list_widget.dart b/lib/src/widgets/chat_list_widget.dart index e19c92d0..87278c3c 100644 --- a/lib/src/widgets/chat_list_widget.dart +++ b/lib/src/widgets/chat_list_widget.dart @@ -35,62 +35,23 @@ class ChatListWidget extends StatefulWidget { const ChatListWidget({ Key? key, required this.chatController, - required this.chatBackgroundConfig, required this.assignReplyMessage, required this.replyMessage, this.loadingWidget, - this.reactionPopupConfig, - this.messageConfig, - this.chatBubbleConfig, - this.profileCircleConfig, - this.swipeToReplyConfig, - this.repliedMessageConfig, - this.typeIndicatorConfig, - this.replyPopupConfig, this.loadMoreData, this.isLastPage, this.onChatListTap, - this.emojiPickerSheetConfig, }) : super(key: key); /// Provides controller for accessing few function for running chat. final ChatController chatController; - /// Provides configuration for background of chat. - final ChatBackgroundConfiguration chatBackgroundConfig; - /// Provides widget for loading view while pagination is enabled. final Widget? loadingWidget; - /// Provides configuration for reaction pop up appearance. - final ReactionPopupConfiguration? reactionPopupConfig; - - /// Provides configuration for customisation of different types - /// messages. - final MessageConfiguration? messageConfig; - - /// Provides configuration of chat bubble's appearance. - final ChatBubbleConfiguration? chatBubbleConfig; - - /// Provides configuration for profile circle avatar of user. - final ProfileCircleConfiguration? profileCircleConfig; - - /// Provides configuration for when user swipe to chat bubble. - final SwipeToReplyConfiguration? swipeToReplyConfig; - - /// Provides configuration for replied message view which is located upon chat - /// bubble. - final RepliedMessageConfiguration? repliedMessageConfig; - - /// Provides configuration of typing indicator's appearance. - final TypeIndicatorConfiguration? typeIndicatorConfig; - /// Provides reply message when user swipe to chat bubble. final ReplyMessage replyMessage; - /// Provides configuration for reply snack bar's appearance and options. - final ReplyPopupConfiguration? replyPopupConfig; - /// Provides callback when user actions reaches to top and needs to load more /// chat final VoidCallBackWithFuture? loadMoreData; @@ -105,9 +66,6 @@ class ChatListWidget extends StatefulWidget { /// Provides callback when user tap anywhere on whole chat. final VoidCallBack? onChatListTap; - /// Configuration for emoji picker sheet - final Config? emojiPickerSheetConfig; - @override State createState() => _ChatListWidgetState(); } @@ -124,9 +82,6 @@ class _ChatListWidgetState extends State ScrollController get scrollController => chatController.scrollController; - ChatBackgroundConfiguration get chatBackgroundConfig => - widget.chatBackgroundConfig; - FeatureActiveConfig? featureActiveConfig; ChatUser? currentUser; @@ -139,9 +94,9 @@ class _ChatListWidgetState extends State @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - featureActiveConfig = provide!.featureActiveConfig; - currentUser = provide!.chatController.currentUser; + if (chatViewIW != null) { + featureActiveConfig = chatViewIW!.featureActiveConfig; + currentUser = chatViewIW!.chatController.currentUser; } if (featureActiveConfig?.enablePagination ?? false) { // When flag is on then it will include pagination logic to scroll @@ -190,15 +145,8 @@ class _ChatListWidgetState extends State scrollController: scrollController, isEnableSwipeToSeeTime: featureActiveConfig?.enableSwipeToSeeTime ?? true, - chatBackgroundConfig: widget.chatBackgroundConfig, assignReplyMessage: widget.assignReplyMessage, replyMessage: widget.replyMessage, - swipeToReplyConfig: widget.swipeToReplyConfig, - repliedMessageConfig: widget.repliedMessageConfig, - profileCircleConfig: widget.profileCircleConfig, - messageConfig: widget.messageConfig, - chatBubbleConfig: widget.chatBubbleConfig, - typeIndicatorConfig: widget.typeIndicatorConfig, onChatBubbleLongPress: (yCoordinate, xCoordinate, message) { if (featureActiveConfig?.enableReactionPopup ?? false) { _reactionPopupKey.currentState?.refreshWidget( @@ -222,10 +170,8 @@ class _ChatListWidgetState extends State if (featureActiveConfig?.enableReactionPopup ?? false) ReactionPopup( key: _reactionPopupKey, - reactionPopupConfig: widget.reactionPopupConfig, onTap: _onChatListTap, showPopUp: showPopupValue, - emojiPickerSheetConfig: widget.emojiPickerSheetConfig, ), ], ); @@ -251,7 +197,7 @@ class _ChatListWidgetState extends State required Message message, required bool sentByCurrentUser, }) { - final replyPopup = widget.replyPopupConfig; + final replyPopup = chatListConfig.replyPopupConfig; ScaffoldMessenger.of(context) .showSnackBar( SnackBar( @@ -310,7 +256,7 @@ class _ChatListWidgetState extends State @override void dispose() { - chatController.messageStreamController.close(); + chatViewIW?.chatController.messageStreamController.close(); scrollController.dispose(); _isNextPageLoading.dispose(); showPopUp.dispose(); diff --git a/lib/src/widgets/chat_view.dart b/lib/src/widgets/chat_view.dart index 22696ff7..0cffe786 100644 --- a/lib/src/widgets/chat_view.dart +++ b/lib/src/widgets/chat_view.dart @@ -21,6 +21,7 @@ */ import 'package:chatview/chatview.dart'; import 'package:chatview/src/extensions/extensions.dart'; +import 'package:chatview/src/inherited_widgets/configurations_inherited_widgets.dart'; import 'package:chatview/src/widgets/chat_list_widget.dart'; import 'package:chatview/src/widgets/chat_view_inherited_widget.dart'; import 'package:chatview/src/widgets/chatview_state_widget.dart'; @@ -211,81 +212,80 @@ class _ChatViewState extends State children: [ if (widget.appBar != null) widget.appBar!, Expanded( - child: Stack( - children: [ - if (chatViewState.isLoading) - ChatViewStateWidget( - chatViewStateWidgetConfig: - chatViewStateConfig?.loadingWidgetConfig, - chatViewState: chatViewState, - ) - else if (chatViewState.noMessages) - ChatViewStateWidget( - chatViewStateWidgetConfig: - chatViewStateConfig?.noMessageWidgetConfig, - chatViewState: chatViewState, - onReloadButtonTap: - chatViewStateConfig?.onReloadButtonTap, - ) - else if (chatViewState.isError) - ChatViewStateWidget( - chatViewStateWidgetConfig: - chatViewStateConfig?.errorWidgetConfig, - chatViewState: chatViewState, - onReloadButtonTap: - chatViewStateConfig?.onReloadButtonTap, - ) - else if (chatViewState.hasMessages) - ValueListenableBuilder( - valueListenable: replyMessage, - builder: (_, state, child) { - return ChatListWidget( - replyMessage: state, - chatController: widget.chatController, - chatBackgroundConfig: widget.chatBackgroundConfig, - reactionPopupConfig: widget.reactionPopupConfig, - typeIndicatorConfig: widget.typeIndicatorConfig, - chatBubbleConfig: widget.chatBubbleConfig, - loadMoreData: widget.loadMoreData, - isLastPage: widget.isLastPage, - replyPopupConfig: widget.replyPopupConfig, - loadingWidget: widget.loadingWidget, - messageConfig: widget.messageConfig, - profileCircleConfig: widget.profileCircleConfig, - repliedMessageConfig: widget.repliedMessageConfig, - swipeToReplyConfig: widget.swipeToReplyConfig, - onChatListTap: widget.onChatListTap, - assignReplyMessage: (message) => _sendMessageKey - .currentState - ?.assignReplyMessage(message), - emojiPickerSheetConfig: - widget.emojiPickerSheetConfig, - ); - }, - ), - if (featureActiveConfig.enableTextField) - SendMessageWidget( - key: _sendMessageKey, - chatController: chatController, - sendMessageBuilder: widget.sendMessageBuilder, - sendMessageConfig: widget.sendMessageConfig, - backgroundColor: chatBackgroundConfig.backgroundColor, - onSendTap: (message, replyMessage, messageType) { - if (context.suggestionsConfig - ?.autoDismissOnSelection ?? - true) { - chatController.removeReplySuggestions(); - } - _onSendTap(message, replyMessage, messageType); - }, - onReplyCallback: (reply) => - replyMessage.value = reply, - onReplyCloseCallback: () => - replyMessage.value = const ReplyMessage(), - messageConfig: widget.messageConfig, - replyMessageBuilder: widget.replyMessageBuilder, - ), - ], + child: ConfigurationsInheritedWidget( + chatBackgroundConfig: widget.chatBackgroundConfig, + reactionPopupConfig: widget.reactionPopupConfig, + typeIndicatorConfig: widget.typeIndicatorConfig, + chatBubbleConfig: widget.chatBubbleConfig, + replyPopupConfig: widget.replyPopupConfig, + messageConfig: widget.messageConfig, + profileCircleConfig: widget.profileCircleConfig, + repliedMessageConfig: widget.repliedMessageConfig, + swipeToReplyConfig: widget.swipeToReplyConfig, + emojiPickerSheetConfig: widget.emojiPickerSheetConfig, + child: Stack( + children: [ + if (chatViewState.isLoading) + ChatViewStateWidget( + chatViewStateWidgetConfig: + chatViewStateConfig?.loadingWidgetConfig, + chatViewState: chatViewState, + ) + else if (chatViewState.noMessages) + ChatViewStateWidget( + chatViewStateWidgetConfig: + chatViewStateConfig?.noMessageWidgetConfig, + chatViewState: chatViewState, + onReloadButtonTap: + chatViewStateConfig?.onReloadButtonTap, + ) + else if (chatViewState.isError) + ChatViewStateWidget( + chatViewStateWidgetConfig: + chatViewStateConfig?.errorWidgetConfig, + chatViewState: chatViewState, + onReloadButtonTap: + chatViewStateConfig?.onReloadButtonTap, + ) + else if (chatViewState.hasMessages) + ValueListenableBuilder( + valueListenable: replyMessage, + builder: (_, state, child) { + return ChatListWidget( + replyMessage: state, + chatController: widget.chatController, + loadMoreData: widget.loadMoreData, + isLastPage: widget.isLastPage, + loadingWidget: widget.loadingWidget, + onChatListTap: widget.onChatListTap, + assignReplyMessage: (message) => _sendMessageKey + .currentState + ?.assignReplyMessage(message), + ); + }, + ), + if (featureActiveConfig.enableTextField) + SendMessageWidget( + key: _sendMessageKey, + sendMessageBuilder: widget.sendMessageBuilder, + sendMessageConfig: widget.sendMessageConfig, + onSendTap: (message, replyMessage, messageType) { + if (context.suggestionsConfig + ?.autoDismissOnSelection ?? + true) { + chatController.removeReplySuggestions(); + } + _onSendTap(message, replyMessage, messageType); + }, + onReplyCallback: (reply) => + replyMessage.value = reply, + onReplyCloseCallback: () => + replyMessage.value = const ReplyMessage(), + messageConfig: widget.messageConfig, + replyMessageBuilder: widget.replyMessageBuilder, + ), + ], + ), ), ), ], diff --git a/lib/src/widgets/emoji_row.dart b/lib/src/widgets/emoji_row.dart index bee84387..c5f39bc2 100644 --- a/lib/src/widgets/emoji_row.dart +++ b/lib/src/widgets/emoji_row.dart @@ -19,9 +19,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import 'package:emoji_picker_flutter/emoji_picker_flutter.dart'; +import 'package:chatview/src/extensions/extensions.dart'; import 'package:flutter/material.dart'; -import 'package:chatview/src/models/reaction_popup_configuration.dart'; import 'package:chatview/src/utils/constants/constants.dart'; import '../values/typedefs.dart'; @@ -31,16 +30,11 @@ class EmojiRow extends StatelessWidget { EmojiRow({ Key? key, required this.onEmojiTap, - this.emojiConfiguration, - this.emojiPickerSheetConfig, }) : super(key: key); /// Provides callback when user taps on emoji in reaction pop-up. final StringCallback onEmojiTap; - /// Provides configuration of emoji's appearance in reaction pop-up. - final EmojiConfiguration? emojiConfiguration; - /// These are default emojis. final List _emojiUnicodes = [ heart, @@ -51,13 +45,11 @@ class EmojiRow extends StatelessWidget { thumbsUp, ]; - /// Configuration for emoji picker sheet - final Config? emojiPickerSheetConfig; - @override Widget build(BuildContext context) { - final emojiList = emojiConfiguration?.emojiList ?? _emojiUnicodes; - final size = emojiConfiguration?.size; + final emojiConfig = context.chatListConfig.reactionPopupConfig?.emojiConfig; + final emojiList = emojiConfig?.emojiList ?? _emojiUnicodes; + final size = emojiConfig?.size; return Row( children: [ Expanded( @@ -91,10 +83,10 @@ class EmojiRow extends StatelessWidget { void _showBottomSheet(BuildContext context) => showModalBottomSheet( context: context, - builder: (context) => EmojiPickerWidget( - emojiPickerSheetConfig: emojiPickerSheetConfig, + builder: (newContext) => EmojiPickerWidget( + emojiPickerSheetConfig: context.chatListConfig.emojiPickerSheetConfig, onSelected: (emoji) { - Navigator.pop(context); + Navigator.pop(newContext); onEmojiTap(emoji); }, ), diff --git a/lib/src/widgets/message_time_widget.dart b/lib/src/widgets/message_time_widget.dart index c542261e..666e922f 100644 --- a/lib/src/widgets/message_time_widget.dart +++ b/lib/src/widgets/message_time_widget.dart @@ -27,8 +27,6 @@ class MessageTimeWidget extends StatelessWidget { Key? key, required this.messageTime, required this.isCurrentUser, - this.messageTimeTextStyle, - this.messageTimeIconColor, }) : super(key: key); /// Provides message crated date time. @@ -37,15 +35,11 @@ class MessageTimeWidget extends StatelessWidget { /// Represents message is sending by current user. final bool isCurrentUser; - /// Provides text style of message created time view. - final TextStyle? messageTimeTextStyle; - - /// Provides color of icon which is showed when user swipe whole chat for - /// seeing message sending time - final Color? messageTimeIconColor; - @override Widget build(BuildContext context) { + final chatBackgroundConfig = context.chatListConfig.chatBackgroundConfig; + final messageTimeIconColor = + chatBackgroundConfig.messageTimeIconColor ?? Colors.black; return Align( alignment: Alignment.centerRight, child: Padding( @@ -58,19 +52,20 @@ class MessageTimeWidget extends StatelessWidget { decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( - color: messageTimeIconColor ?? Colors.black, + color: messageTimeIconColor, ), ), child: Icon( isCurrentUser ? Icons.arrow_forward : Icons.arrow_back, size: 10, - color: messageTimeIconColor ?? Colors.black, + color: messageTimeIconColor, ), ), const SizedBox(width: 4), Text( messageTime.getTimeFromDateTime, - style: messageTimeTextStyle ?? const TextStyle(fontSize: 12), + style: chatBackgroundConfig.messageTimeTextStyle ?? + const TextStyle(fontSize: 12), ), ], ), diff --git a/lib/src/widgets/reaction_popup.dart b/lib/src/widgets/reaction_popup.dart index a5ef709c..4fc10c1c 100644 --- a/lib/src/widgets/reaction_popup.dart +++ b/lib/src/widgets/reaction_popup.dart @@ -29,35 +29,36 @@ import 'emoji_row.dart'; class ReactionPopup extends StatefulWidget { const ReactionPopup({ Key? key, - this.reactionPopupConfig, required this.onTap, required this.showPopUp, - this.emojiPickerSheetConfig, }) : super(key: key); - /// Provides configuration of reaction pop-up appearance. - final ReactionPopupConfiguration? reactionPopupConfig; - /// Provides call back when user taps on reaction pop-up. final VoidCallBack onTap; /// Represents should pop-up show or not. final bool showPopUp; - /// Configuration for emoji picker sheet - final Config? emojiPickerSheetConfig; - @override ReactionPopupState createState() => ReactionPopupState(); } class ReactionPopupState extends State with SingleTickerProviderStateMixin { - late AnimationController _animationController; - late Animation _scaleAnimation; + late final AnimationController _animationController = AnimationController( + vsync: this, + duration: reactionPopupConfig?.animationDuration ?? + const Duration(milliseconds: 180), + ); + + late final Animation _scaleAnimation = CurvedAnimation( + parent: _animationController, + curve: Curves.easeIn, + reverseCurve: Curves.easeInOutSine, + ); ReactionPopupConfiguration? get reactionPopupConfig => - widget.reactionPopupConfig; + chatListConfig.reactionPopupConfig; bool get showPopUp => widget.showPopUp; double _yCoordinate = 0.0; @@ -70,27 +71,13 @@ class ReactionPopupState extends State @override void initState() { super.initState(); - _initializeAnimationControllers(); - } - - void _initializeAnimationControllers() { - _animationController = AnimationController( - vsync: this, - duration: widget.reactionPopupConfig?.animationDuration ?? - const Duration(milliseconds: 180), - ); - _scaleAnimation = CurvedAnimation( - parent: _animationController, - curve: Curves.easeIn, - reverseCurve: Curves.easeInOutSine, - ); } @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - chatController = provide!.chatController; + if (chatViewIW != null) { + chatController = chatViewIW!.chatController; currentUser = chatController?.currentUser; } } @@ -171,8 +158,6 @@ class ReactionPopupState extends State ); } }, - emojiConfiguration: reactionPopupConfig?.emojiConfig, - emojiPickerSheetConfig: widget.emojiPickerSheetConfig, ); void refreshWidget({ diff --git a/lib/src/widgets/reaction_widget.dart b/lib/src/widgets/reaction_widget.dart index 1a4d084e..8d1ed9d6 100644 --- a/lib/src/widgets/reaction_widget.dart +++ b/lib/src/widgets/reaction_widget.dart @@ -58,8 +58,8 @@ class _ReactionWidgetState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - chatController = provide!.chatController; + if (chatViewIW != null) { + chatController = chatViewIW!.chatController; } } diff --git a/lib/src/widgets/send_message_widget.dart b/lib/src/widgets/send_message_widget.dart index e8b5c123..d69ec8ee 100644 --- a/lib/src/widgets/send_message_widget.dart +++ b/lib/src/widgets/send_message_widget.dart @@ -35,9 +35,7 @@ class SendMessageWidget extends StatefulWidget { const SendMessageWidget({ Key? key, required this.onSendTap, - required this.chatController, this.sendMessageConfig, - this.backgroundColor, this.sendMessageBuilder, this.onReplyCallback, this.onReplyCloseCallback, @@ -51,8 +49,6 @@ class SendMessageWidget extends StatefulWidget { /// Provides configuration for text field appearance. final SendMessageConfiguration? sendMessageConfig; - /// Allow user to set background colour. - final Color? backgroundColor; /// Allow user to set custom text field. final ReplyMessageWithReturnWidget? sendMessageBuilder; @@ -63,9 +59,6 @@ class SendMessageWidget extends StatefulWidget { /// Provides call when user tap on close button which is showed in reply pop-up. final VoidCallBack? onReplyCloseCallback; - /// Provides controller for accessing few function for running chat. - final ChatController chatController; - /// Provides configuration of all types of messages. final MessageConfiguration? messageConfig; @@ -85,7 +78,7 @@ class SendMessageWidgetState extends State { final _focusNode = FocusNode(); ChatUser? get repliedUser => replyMessage.replyTo.isNotEmpty - ? widget.chatController.getUserFromId(replyMessage.replyTo) + ? chatViewIW?.chatController.getUserFromId(replyMessage.replyTo) : null; String get _replyTo => replyMessage.replyTo == currentUser?.id @@ -97,8 +90,8 @@ class SendMessageWidgetState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - currentUser = provide!.chatController.currentUser; + if (chatViewIW != null) { + currentUser = chatViewIW!.chatController.currentUser; } } @@ -122,11 +115,11 @@ class SendMessageWidgetState extends State { child: Container( height: MediaQuery.of(context).size.height / ((!kIsWeb && Platform.isIOS) ? 24 : 28), - color: widget.backgroundColor ?? Colors.white, + color: chatListConfig.chatBackgroundConfig.backgroundColor ?? Colors.white, ), ), Padding( - key: provide?.chatTextFieldViewKey, + key: chatViewIW?.chatTextFieldViewKey, padding: EdgeInsets.fromLTRB( bottomPadding4, bottomPadding4, diff --git a/lib/src/widgets/suggestions/suggestion_item.dart b/lib/src/widgets/suggestions/suggestion_item.dart index 025c26ec..cd7cd7e5 100644 --- a/lib/src/widgets/suggestions/suggestion_item.dart +++ b/lib/src/widgets/suggestions/suggestion_item.dart @@ -20,7 +20,7 @@ class SuggestionItem extends StatelessWidget { onTap: () { suggestionsConfig.onTap?.call(suggestionItemData); if (suggestionsConfig.autoDismissOnSelection) { - context.provide?.chatController.removeReplySuggestions(); + context.chatViewIW?.chatController.removeReplySuggestions(); } }, child: Container( diff --git a/lib/src/widgets/suggestions/suggestion_list.dart b/lib/src/widgets/suggestions/suggestion_list.dart index a8c27195..97799a29 100644 --- a/lib/src/widgets/suggestions/suggestion_list.dart +++ b/lib/src/widgets/suggestions/suggestion_list.dart @@ -29,7 +29,7 @@ class _SuggestionListState extends State vsync: this, )..addListener(updateSuggestionsOnAnimation); WidgetsBinding.instance.addPostFrameCallback((_) { - final newSuggestions = provide?.chatController.newSuggestions; + final newSuggestions = chatViewIW?.chatController.newSuggestions; newSuggestions?.addListener(animateSuggestionList); }); } @@ -37,21 +37,21 @@ class _SuggestionListState extends State void updateSuggestionsOnAnimation() { if (isSuggestionListEmpty && _controller.value == 0) { suggestions = []; - } else if (provide?.chatController.newSuggestions.value.isNotEmpty ?? + } else if (chatViewIW?.chatController.newSuggestions.value.isNotEmpty ?? false) { - suggestions = provide?.chatController.newSuggestions.value ?? []; + suggestions = chatViewIW?.chatController.newSuggestions.value ?? []; } } @override void activate() { super.activate(); - final newSuggestions = provide?.chatController.newSuggestions; + final newSuggestions = chatViewIW?.chatController.newSuggestions; newSuggestions?.addListener(animateSuggestionList); } void animateSuggestionList() { - final newSuggestions = provide?.chatController.newSuggestions; + final newSuggestions = chatViewIW?.chatController.newSuggestions; if (newSuggestions != null) { isSuggestionListEmpty = newSuggestions.value.isEmpty; isSuggestionListEmpty ? _controller.reverse() : _controller.forward(); @@ -113,7 +113,7 @@ class _SuggestionListState extends State @override void deactivate() { - final newSuggestions = provide?.chatController.newSuggestions; + final newSuggestions = chatViewIW?.chatController.newSuggestions; newSuggestions?.removeListener(animateSuggestionList); super.deactivate(); } diff --git a/lib/src/widgets/type_indicator_widget.dart b/lib/src/widgets/type_indicator_widget.dart index aaf65c7a..8a97b5ee 100644 --- a/lib/src/widgets/type_indicator_widget.dart +++ b/lib/src/widgets/type_indicator_widget.dart @@ -163,8 +163,8 @@ class _TypingIndicatorState extends State @override void didChangeDependencies() { super.didChangeDependencies(); - if (provide != null) { - profileCircleConfiguration = provide!.profileCircleConfiguration; + if (chatViewIW != null) { + profileCircleConfiguration = chatViewIW!.profileCircleConfiguration; } }