Skip to content

Commit

Permalink
feat: 🌟 listen to typing indicator changes better
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbadstuebner authored and aditya-css committed Jun 20, 2024
1 parent e8f7204 commit 42d2fdf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
56 changes: 21 additions & 35 deletions lib/src/widgets/chat_groupedlist_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ChatGroupedListWidget extends StatefulWidget {
const ChatGroupedListWidget({
Key? key,
required this.showPopUp,
required this.showTypingIndicator,
required this.scrollController,
required this.chatBackgroundConfig,
required this.replyMessage,
Expand All @@ -52,8 +51,7 @@ class ChatGroupedListWidget extends StatefulWidget {
/// Allow user to swipe to see time while reaction pop is not open.
final bool showPopUp;

/// Allow user to show typing indicator.
final bool showTypingIndicator;
/// Pass scroll controller
final ScrollController scrollController;

/// Allow user to give customisation to background of chat
Expand Down Expand Up @@ -103,8 +101,6 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>

bool get showPopUp => widget.showPopUp;

bool get showTypingIndicator => widget.showTypingIndicator;

bool highlightMessage = false;
final ValueNotifier<String?> _replyId = ValueNotifier(null);

Expand Down Expand Up @@ -184,7 +180,6 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
reverse: true,
// When reaction popup is being appeared at that user should not scroll.
physics: showPopUp ? const NeverScrollableScrollPhysics() : null,
padding: EdgeInsets.only(bottom: showTypingIndicator ? 50 : 0),
controller: widget.scrollController,
child: Column(
mainAxisSize: MainAxisSize.min,
Expand All @@ -210,38 +205,29 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
)
: _chatStreamBuilder,
),
widget.showTypingIndicator
? TypingIndicator(
typeIndicatorConfig: widget.typeIndicatorConfig,
chatBubbleConfig: chatBubbleConfig?.inComingChatBubbleConfig,
showIndicator: widget.showTypingIndicator,
)
: ValueListenableBuilder(
valueListenable: ChatViewInheritedWidget.of(context)!
.chatController
.typingIndicatorNotifier,
builder: (context, value, child) => TypingIndicator(
typeIndicatorConfig: widget.typeIndicatorConfig,
chatBubbleConfig:
chatBubbleConfig?.inComingChatBubbleConfig,
showIndicator: value,
),
if (chatController != null)
ValueListenableBuilder(
valueListenable: chatController!.typingIndicatorNotifier,
builder: (context, value, child) => TypingIndicator(
typeIndicatorConfig: widget.typeIndicatorConfig,
chatBubbleConfig: chatBubbleConfig?.inComingChatBubbleConfig,
showIndicator: value,
),
),
if (chatController != null)
Flexible(
child: Align(
alignment: suggestionsListConfig.axisAlignment.alignment,
child: ValueListenableBuilder(
valueListenable: chatController!.newSuggestions,
builder: (context, value, child) {
return SuggestionList(
suggestions: value,
);
},
),
Flexible(
child: Align(
alignment: suggestionsListConfig.axisAlignment.alignment,
child: ValueListenableBuilder(
valueListenable: ChatViewInheritedWidget.of(context)!
.chatController
.newSuggestions,
builder: (context, value, child) {
return SuggestionList(
suggestions: value,
);
},
),
),
),

// Adds bottom space to the message list, ensuring it is displayed
// above the message text field.
Expand Down
7 changes: 0 additions & 7 deletions lib/src/widgets/chat_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ChatListWidget extends StatefulWidget {
Key? key,
required this.chatController,
required this.chatBackgroundConfig,
required this.showTypingIndicator,
required this.assignReplyMessage,
required this.replyMessage,
this.loadingWidget,
Expand All @@ -63,9 +62,6 @@ class ChatListWidget extends StatefulWidget {
/// Provides widget for loading view while pagination is enabled.
final Widget? loadingWidget;

/// Provides flag for turn on/off typing indicator.
final bool showTypingIndicator;

/// Provides configuration for reaction pop up appearance.
final ReactionPopupConfiguration? reactionPopupConfig;

Expand Down Expand Up @@ -128,8 +124,6 @@ class _ChatListWidgetState extends State<ChatListWidget>

ScrollController get scrollController => chatController.scrollController;

bool get showTypingIndicator => widget.showTypingIndicator;

ChatBackgroundConfiguration get chatBackgroundConfig =>
widget.chatBackgroundConfig;

Expand Down Expand Up @@ -193,7 +187,6 @@ class _ChatListWidgetState extends State<ChatListWidget>
children: [
ChatGroupedListWidget(
showPopUp: showPopupValue,
showTypingIndicator: showTypingIndicator,
scrollController: scrollController,
isEnableSwipeToSeeTime:
featureActiveConfig?.enableSwipeToSeeTime ?? true,
Expand Down
4 changes: 0 additions & 4 deletions lib/src/widgets/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ class _ChatViewState extends State<ChatView>

ChatController get chatController => widget.chatController;

// bool get showTypingIndicator => widget.showTypingIndicator;

ChatBackgroundConfiguration get chatBackgroundConfig =>
widget.chatBackgroundConfig;

Expand Down Expand Up @@ -242,8 +240,6 @@ class _ChatViewState extends State<ChatView>
valueListenable: replyMessage,
builder: (_, state, child) {
return ChatListWidget(
showTypingIndicator:
chatController.showTypingIndicator,
replyMessage: state,
chatController: widget.chatController,
chatBackgroundConfig: widget.chatBackgroundConfig,
Expand Down

0 comments on commit 42d2fdf

Please sign in to comment.