Skip to content

Commit

Permalink
feat: 🌟 use column instead of stack to remove arbitrary paddings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbadstuebner committed Jun 18, 2024
1 parent 232214c commit 5624473
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 88 deletions.
15 changes: 6 additions & 9 deletions lib/src/widgets/chat_groupedlist_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,15 @@ class _ChatGroupedListWidgetState extends State<ChatGroupedListWidget>
valueListenable: ChatViewInheritedWidget.of(context)!
.chatController
.newSuggestions,
builder: (context, value, child) {
return SuggestionList(
suggestions: value,
);
},
builder: (context, value, child) => SuggestionList(
suggestions: value,
),
),
),
),

// Adds bottom space to the message list, ensuring it is displayed
// above the message text field.
const SizedBox(height: 100),
SizedBox(
height: MediaQuery.of(context).size.height,
),
],
),
);
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/chat_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
valueListenable: showPopUp,
builder: (_, showPopupValue, child) {
return Stack(
clipBehavior: Clip.none,
children: [
ChatGroupedListWidget(
showPopUp: showPopupValue,
Expand Down
170 changes: 92 additions & 78 deletions lib/src/widgets/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,85 +220,99 @@ class _ChatViewState extends State<ChatView>
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<ReplyMessage>(
valueListenable: replyMessage,
builder: (_, state, child) {
return ChatListWidget(
showTypingIndicator:
chatController.showTypingIndicator,
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: [
if (chatViewState.isLoading)
ChatViewStateWidget(
chatViewStateWidgetConfig:
chatViewStateConfig?.loadingWidgetConfig,
fallbackTitle: "Loading…",
chatViewState: chatViewState,
)
else if (chatViewState.noMessages)
ChatViewStateWidget(
chatViewStateWidgetConfig:
chatViewStateConfig?.noMessageWidgetConfig,
fallbackTitle: "No messages yet.",
chatViewState: chatViewState,
onReloadButtonTap:
chatViewStateConfig?.onReloadButtonTap,
)
else if (chatViewState.isError)
ChatViewStateWidget(
chatViewStateWidgetConfig:
chatViewStateConfig?.errorWidgetConfig,
fallbackTitle: "Error",
chatViewState: chatViewState,
onReloadButtonTap:
chatViewStateConfig?.onReloadButtonTap,
)
else if (chatViewState.hasMessages)
Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
bottom: -MediaQuery.of(context).size.height,
child: ValueListenableBuilder<ReplyMessage>(
valueListenable: replyMessage,
builder: (_, state, child) {
return ChatListWidget(
showTypingIndicator:
chatController.showTypingIndicator,
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,
);
},
),
)
],
)
else
Container(),
][0],
),
if (featureActiveConfig.enableTextField)
SendMessageWidget(
key: _sendMessageKey,
chatController: chatController,
sendMessageBuilder: widget.sendMessageBuilder,
sendMessageConfig: widget.sendMessageConfig,
backgroundColor: Colors.transparent,
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,
),
],
),
);
Expand Down
7 changes: 6 additions & 1 deletion lib/src/widgets/chatview_state_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ChatViewStateWidget extends StatelessWidget {
const ChatViewStateWidget({
Key? key,
this.chatViewStateWidgetConfig,
required this.fallbackTitle,
required this.chatViewState,
this.onReloadButtonTap,
}) : super(key: key);
Expand All @@ -17,6 +18,9 @@ class ChatViewStateWidget extends StatelessWidget {
/// Provides current state of chat view.
final ChatViewState chatViewState;

/// Fallback if no title is given via config.
final String fallbackTitle;

/// Provides callback when user taps on reload button in error and no messages
/// state.
final VoidCallBack? onReloadButtonTap;
Expand All @@ -31,7 +35,8 @@ class ChatViewStateWidget extends StatelessWidget {
children: [
Text(
(chatViewStateWidgetConfig?.title
.getChatViewStateTitle(chatViewState))!,
.getChatViewStateTitle(chatViewState)) ??
fallbackTitle,
style: chatViewStateWidgetConfig?.titleTextStyle ??
const TextStyle(
fontSize: 22,
Expand Down

0 comments on commit 5624473

Please sign in to comment.