Skip to content

Commit 42d2fdf

Browse files
jonasbadstuebneraditya-css
authored andcommitted
feat: 🌟 listen to typing indicator changes better
1 parent e8f7204 commit 42d2fdf

File tree

3 files changed

+21
-46
lines changed

3 files changed

+21
-46
lines changed

lib/src/widgets/chat_groupedlist_widget.dart

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class ChatGroupedListWidget extends StatefulWidget {
3333
const ChatGroupedListWidget({
3434
Key? key,
3535
required this.showPopUp,
36-
required this.showTypingIndicator,
3736
required this.scrollController,
3837
required this.chatBackgroundConfig,
3938
required this.replyMessage,
@@ -52,8 +51,7 @@ class ChatGroupedListWidget extends StatefulWidget {
5251
/// Allow user to swipe to see time while reaction pop is not open.
5352
final bool showPopUp;
5453

55-
/// Allow user to show typing indicator.
56-
final bool showTypingIndicator;
54+
/// Pass scroll controller
5755
final ScrollController scrollController;
5856

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

104102
bool get showPopUp => widget.showPopUp;
105103

106-
bool get showTypingIndicator => widget.showTypingIndicator;
107-
108104
bool highlightMessage = false;
109105
final ValueNotifier<String?> _replyId = ValueNotifier(null);
110106

@@ -184,7 +180,6 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
184180
reverse: true,
185181
// When reaction popup is being appeared at that user should not scroll.
186182
physics: showPopUp ? const NeverScrollableScrollPhysics() : null,
187-
padding: EdgeInsets.only(bottom: showTypingIndicator ? 50 : 0),
188183
controller: widget.scrollController,
189184
child: Column(
190185
mainAxisSize: MainAxisSize.min,
@@ -210,38 +205,29 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
210205
)
211206
: _chatStreamBuilder,
212207
),
213-
widget.showTypingIndicator
214-
? TypingIndicator(
215-
typeIndicatorConfig: widget.typeIndicatorConfig,
216-
chatBubbleConfig: chatBubbleConfig?.inComingChatBubbleConfig,
217-
showIndicator: widget.showTypingIndicator,
218-
)
219-
: ValueListenableBuilder(
220-
valueListenable: ChatViewInheritedWidget.of(context)!
221-
.chatController
222-
.typingIndicatorNotifier,
223-
builder: (context, value, child) => TypingIndicator(
224-
typeIndicatorConfig: widget.typeIndicatorConfig,
225-
chatBubbleConfig:
226-
chatBubbleConfig?.inComingChatBubbleConfig,
227-
showIndicator: value,
228-
),
208+
if (chatController != null)
209+
ValueListenableBuilder(
210+
valueListenable: chatController!.typingIndicatorNotifier,
211+
builder: (context, value, child) => TypingIndicator(
212+
typeIndicatorConfig: widget.typeIndicatorConfig,
213+
chatBubbleConfig: chatBubbleConfig?.inComingChatBubbleConfig,
214+
showIndicator: value,
215+
),
216+
),
217+
if (chatController != null)
218+
Flexible(
219+
child: Align(
220+
alignment: suggestionsListConfig.axisAlignment.alignment,
221+
child: ValueListenableBuilder(
222+
valueListenable: chatController!.newSuggestions,
223+
builder: (context, value, child) {
224+
return SuggestionList(
225+
suggestions: value,
226+
);
227+
},
229228
),
230-
Flexible(
231-
child: Align(
232-
alignment: suggestionsListConfig.axisAlignment.alignment,
233-
child: ValueListenableBuilder(
234-
valueListenable: ChatViewInheritedWidget.of(context)!
235-
.chatController
236-
.newSuggestions,
237-
builder: (context, value, child) {
238-
return SuggestionList(
239-
suggestions: value,
240-
);
241-
},
242229
),
243230
),
244-
),
245231

246232
// Adds bottom space to the message list, ensuring it is displayed
247233
// above the message text field.

lib/src/widgets/chat_list_widget.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class ChatListWidget extends StatefulWidget {
3636
Key? key,
3737
required this.chatController,
3838
required this.chatBackgroundConfig,
39-
required this.showTypingIndicator,
4039
required this.assignReplyMessage,
4140
required this.replyMessage,
4241
this.loadingWidget,
@@ -63,9 +62,6 @@ class ChatListWidget extends StatefulWidget {
6362
/// Provides widget for loading view while pagination is enabled.
6463
final Widget? loadingWidget;
6564

66-
/// Provides flag for turn on/off typing indicator.
67-
final bool showTypingIndicator;
68-
6965
/// Provides configuration for reaction pop up appearance.
7066
final ReactionPopupConfiguration? reactionPopupConfig;
7167

@@ -128,8 +124,6 @@ class _ChatListWidgetState extends State<ChatListWidget>
128124

129125
ScrollController get scrollController => chatController.scrollController;
130126

131-
bool get showTypingIndicator => widget.showTypingIndicator;
132-
133127
ChatBackgroundConfiguration get chatBackgroundConfig =>
134128
widget.chatBackgroundConfig;
135129

@@ -193,7 +187,6 @@ class _ChatListWidgetState extends State<ChatListWidget>
193187
children: [
194188
ChatGroupedListWidget(
195189
showPopUp: showPopupValue,
196-
showTypingIndicator: showTypingIndicator,
197190
scrollController: scrollController,
198191
isEnableSwipeToSeeTime:
199192
featureActiveConfig?.enableSwipeToSeeTime ?? true,

lib/src/widgets/chat_view.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ class _ChatViewState extends State<ChatView>
160160

161161
ChatController get chatController => widget.chatController;
162162

163-
// bool get showTypingIndicator => widget.showTypingIndicator;
164-
165163
ChatBackgroundConfiguration get chatBackgroundConfig =>
166164
widget.chatBackgroundConfig;
167165

@@ -242,8 +240,6 @@ class _ChatViewState extends State<ChatView>
242240
valueListenable: replyMessage,
243241
builder: (_, state, child) {
244242
return ChatListWidget(
245-
showTypingIndicator:
246-
chatController.showTypingIndicator,
247243
replyMessage: state,
248244
chatController: widget.chatController,
249245
chatBackgroundConfig: widget.chatBackgroundConfig,

0 commit comments

Comments
 (0)