Skip to content

Commit 83b5896

Browse files
feat: 🌟 use column instead of stack to remove arbitrary paddings
1 parent b982ec5 commit 83b5896

File tree

4 files changed

+107
-105
lines changed

4 files changed

+107
-105
lines changed

lib/src/widgets/chat_groupedlist_widget.dart

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,29 +121,10 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
121121

122122
bool get isEnableSwipeToSeeTime => widget.isEnableSwipeToSeeTime;
123123

124-
double chatTextFieldHeight = 0;
125-
126124
@override
127125
void initState() {
128126
super.initState();
129127
_initializeAnimation();
130-
updateChatTextFieldHeight();
131-
}
132-
133-
@override
134-
void didUpdateWidget(covariant ChatGroupedListWidget oldWidget) {
135-
super.didUpdateWidget(oldWidget);
136-
updateChatTextFieldHeight();
137-
}
138-
139-
void updateChatTextFieldHeight() {
140-
WidgetsBinding.instance.addPostFrameCallback((_) {
141-
if (!mounted) return;
142-
setState(() {
143-
chatTextFieldHeight =
144-
provide?.chatTextFieldViewKey.currentContext?.size?.height ?? 10;
145-
});
146-
});
147128
}
148129

149130
void _initializeAnimation() {
@@ -184,7 +165,6 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
184165
reverse: true,
185166
// When reaction popup is being appeared at that user should not scroll.
186167
physics: showPopUp ? const NeverScrollableScrollPhysics() : null,
187-
padding: EdgeInsets.only(bottom: showTypingIndicator ? 50 : 0),
188168
controller: widget.scrollController,
189169
child: Column(
190170
mainAxisSize: MainAxisSize.min,
@@ -234,19 +214,17 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
234214
valueListenable: ChatViewInheritedWidget.of(context)!
235215
.chatController
236216
.newSuggestions,
237-
builder: (context, value, child) {
238-
return SuggestionList(
239-
suggestions: value,
240-
);
241-
},
217+
builder: (context, value, child) => SuggestionList(
218+
suggestions: value,
219+
),
242220
),
243221
),
244222
),
245223

246224
// Adds bottom space to the message list, ensuring it is displayed
247225
// above the message text field.
248226
SizedBox(
249-
height: chatTextFieldHeight,
227+
height: MediaQuery.of(context).size.height,
250228
),
251229
],
252230
),

lib/src/widgets/chat_list_widget.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
190190
valueListenable: showPopUp,
191191
builder: (_, showPopupValue, child) {
192192
return Stack(
193+
clipBehavior: Clip.none,
193194
children: [
194195
ChatGroupedListWidget(
195196
showPopUp: showPopupValue,

lib/src/widgets/chat_view.dart

Lines changed: 96 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -213,85 +213,103 @@ class _ChatViewState extends State<ChatView>
213213
children: [
214214
if (widget.appBar != null) widget.appBar!,
215215
Expanded(
216-
child: Stack(
217-
children: [
218-
if (chatViewState.isLoading)
219-
ChatViewStateWidget(
220-
chatViewStateWidgetConfig:
221-
chatViewStateConfig?.loadingWidgetConfig,
222-
chatViewState: chatViewState,
223-
)
224-
else if (chatViewState.noMessages)
225-
ChatViewStateWidget(
226-
chatViewStateWidgetConfig:
227-
chatViewStateConfig?.noMessageWidgetConfig,
228-
chatViewState: chatViewState,
229-
onReloadButtonTap:
230-
chatViewStateConfig?.onReloadButtonTap,
231-
)
232-
else if (chatViewState.isError)
233-
ChatViewStateWidget(
234-
chatViewStateWidgetConfig:
235-
chatViewStateConfig?.errorWidgetConfig,
236-
chatViewState: chatViewState,
237-
onReloadButtonTap:
238-
chatViewStateConfig?.onReloadButtonTap,
239-
)
240-
else if (chatViewState.hasMessages)
241-
ValueListenableBuilder<ReplyMessage>(
242-
valueListenable: replyMessage,
243-
builder: (_, state, child) {
244-
return ChatListWidget(
245-
showTypingIndicator:
246-
chatController.showTypingIndicator,
247-
replyMessage: state,
248-
chatController: widget.chatController,
249-
chatBackgroundConfig: widget.chatBackgroundConfig,
250-
reactionPopupConfig: widget.reactionPopupConfig,
251-
typeIndicatorConfig: widget.typeIndicatorConfig,
252-
chatBubbleConfig: widget.chatBubbleConfig,
253-
loadMoreData: widget.loadMoreData,
254-
isLastPage: widget.isLastPage,
255-
replyPopupConfig: widget.replyPopupConfig,
256-
loadingWidget: widget.loadingWidget,
257-
messageConfig: widget.messageConfig,
258-
profileCircleConfig: widget.profileCircleConfig,
259-
repliedMessageConfig: widget.repliedMessageConfig,
260-
swipeToReplyConfig: widget.swipeToReplyConfig,
261-
onChatListTap: widget.onChatListTap,
262-
assignReplyMessage: (message) => _sendMessageKey
263-
.currentState
264-
?.assignReplyMessage(message),
265-
emojiPickerSheetConfig:
266-
widget.emojiPickerSheetConfig,
267-
);
268-
},
269-
),
270-
if (featureActiveConfig.enableTextField)
271-
SendMessageWidget(
272-
key: _sendMessageKey,
273-
chatController: chatController,
274-
sendMessageBuilder: widget.sendMessageBuilder,
275-
sendMessageConfig: widget.sendMessageConfig,
276-
backgroundColor: chatBackgroundConfig.backgroundColor,
277-
onSendTap: (message, replyMessage, messageType) {
278-
if (context.suggestionsConfig
279-
?.autoDismissOnSelection ??
280-
true) {
281-
chatController.removeReplySuggestions();
282-
}
283-
_onSendTap(message, replyMessage, messageType);
284-
},
285-
onReplyCallback: (reply) =>
286-
replyMessage.value = reply,
287-
onReplyCloseCallback: () =>
288-
replyMessage.value = const ReplyMessage(),
289-
messageConfig: widget.messageConfig,
290-
replyMessageBuilder: widget.replyMessageBuilder,
291-
),
292-
],
293-
),
216+
child: [
217+
if (chatViewState.isLoading)
218+
ChatViewStateWidget(
219+
chatViewStateWidgetConfig:
220+
chatViewStateConfig?.loadingWidgetConfig,
221+
fallbackTitle: "Loading…",
222+
chatViewState: chatViewState,
223+
)
224+
else if (chatViewState.noMessages)
225+
ChatViewStateWidget(
226+
chatViewStateWidgetConfig:
227+
chatViewStateConfig?.noMessageWidgetConfig,
228+
fallbackTitle: "No messages yet.",
229+
chatViewState: chatViewState,
230+
onReloadButtonTap:
231+
chatViewStateConfig?.onReloadButtonTap,
232+
)
233+
else if (chatViewState.isError)
234+
ChatViewStateWidget(
235+
chatViewStateWidgetConfig:
236+
chatViewStateConfig?.errorWidgetConfig,
237+
fallbackTitle: "Error",
238+
chatViewState: chatViewState,
239+
onReloadButtonTap:
240+
chatViewStateConfig?.onReloadButtonTap,
241+
)
242+
else if (chatViewState.hasMessages)
243+
Stack(
244+
clipBehavior: Clip.none,
245+
children: [
246+
Positioned.fill(
247+
bottom: -MediaQuery.of(context).size.height,
248+
child: ValueListenableBuilder<ReplyMessage>(
249+
valueListenable: replyMessage,
250+
builder: (_, state, child) {
251+
return Container(
252+
color: Colors.amber,
253+
child: ChatListWidget(
254+
showTypingIndicator:
255+
chatController.showTypingIndicator,
256+
replyMessage: state,
257+
chatController: widget.chatController,
258+
chatBackgroundConfig:
259+
widget.chatBackgroundConfig,
260+
reactionPopupConfig:
261+
widget.reactionPopupConfig,
262+
typeIndicatorConfig:
263+
widget.typeIndicatorConfig,
264+
chatBubbleConfig: widget.chatBubbleConfig,
265+
loadMoreData: widget.loadMoreData,
266+
isLastPage: widget.isLastPage,
267+
replyPopupConfig: widget.replyPopupConfig,
268+
loadingWidget: widget.loadingWidget,
269+
messageConfig: widget.messageConfig,
270+
profileCircleConfig:
271+
widget.profileCircleConfig,
272+
repliedMessageConfig:
273+
widget.repliedMessageConfig,
274+
swipeToReplyConfig:
275+
widget.swipeToReplyConfig,
276+
onChatListTap: widget.onChatListTap,
277+
assignReplyMessage: (message) =>
278+
_sendMessageKey.currentState
279+
?.assignReplyMessage(message),
280+
emojiPickerSheetConfig:
281+
widget.emojiPickerSheetConfig,
282+
),
283+
);
284+
},
285+
),
286+
)
287+
],
288+
)
289+
else
290+
Container(),
291+
][0],
294292
),
293+
if (featureActiveConfig.enableTextField)
294+
SendMessageWidget(
295+
key: _sendMessageKey,
296+
chatController: chatController,
297+
sendMessageBuilder: widget.sendMessageBuilder,
298+
sendMessageConfig: widget.sendMessageConfig,
299+
backgroundColor: Colors.transparent,
300+
onSendTap: (message, replyMessage, messageType) {
301+
if (context.suggestionsConfig?.autoDismissOnSelection ??
302+
true) {
303+
chatController.removeReplySuggestions();
304+
}
305+
_onSendTap(message, replyMessage, messageType);
306+
},
307+
onReplyCallback: (reply) => replyMessage.value = reply,
308+
onReplyCloseCallback: () =>
309+
replyMessage.value = const ReplyMessage(),
310+
messageConfig: widget.messageConfig,
311+
replyMessageBuilder: widget.replyMessageBuilder,
312+
),
295313
],
296314
),
297315
);

lib/src/widgets/chatview_state_widget.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ChatViewStateWidget extends StatelessWidget {
66
const ChatViewStateWidget({
77
Key? key,
88
this.chatViewStateWidgetConfig,
9+
required this.fallbackTitle,
910
required this.chatViewState,
1011
this.onReloadButtonTap,
1112
}) : super(key: key);
@@ -17,6 +18,9 @@ class ChatViewStateWidget extends StatelessWidget {
1718
/// Provides current state of chat view.
1819
final ChatViewState chatViewState;
1920

21+
/// Fallback if no title is given via config.
22+
final String fallbackTitle;
23+
2024
/// Provides callback when user taps on reload button in error and no messages
2125
/// state.
2226
final VoidCallBack? onReloadButtonTap;
@@ -31,7 +35,8 @@ class ChatViewStateWidget extends StatelessWidget {
3135
children: [
3236
Text(
3337
(chatViewStateWidgetConfig?.title
34-
.getChatViewStateTitle(chatViewState))!,
38+
.getChatViewStateTitle(chatViewState)) ??
39+
fallbackTitle,
3540
style: chatViewStateWidgetConfig?.titleTextStyle ??
3641
const TextStyle(
3742
fontSize: 22,

0 commit comments

Comments
 (0)