diff --git a/CHANGELOG.md b/CHANGELOG.md index 61e8b74..4c8d777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Added autoScrollTriggerOffset to the ChatPaginationControls to adjust when the auto scroll should be enabled - Added the ability to set the color of the CircularProgressIndicator of the ImageLoadingSnackbar by theme.snackBarTheme.actionTextColor - Added semantics for variable text, buttons and textfields +- Added flag to enable/disable loading new and old messages on scrolling to the end of the current view. ## 4.0.0 - Move to the new user story architecture diff --git a/packages/flutter_chat/lib/src/config/chat_options.dart b/packages/flutter_chat/lib/src/config/chat_options.dart index 9dbf314..bace1a3 100644 --- a/packages/flutter_chat/lib/src/config/chat_options.dart +++ b/packages/flutter_chat/lib/src/config/chat_options.dart @@ -302,6 +302,8 @@ class ChatPaginationControls { this.autoScrollTriggerOffset = 50.0, this.loadingIndicatorForNewMessages = true, this.loadingIndicatorForOldMessages = true, + this.loadNewMessagesOnScroll = true, + this.loadOldMessagesOnScroll = true, this.loadingNewMessageMinDuration = Duration.zero, this.loadingOldMessageMinDuration = Duration.zero, }); @@ -314,6 +316,15 @@ class ChatPaginationControls { /// chat. Defaults to 50.0 final double autoScrollTriggerOffset; + /// Whether to load new messages when someone scrolls to the end of the chat + final bool loadNewMessagesOnScroll; + + /// Whether to load older messages when scrolling towards the start of the + /// chat. + /// + /// If the messages are loaded by pagination, it is smart to add this. + final bool loadOldMessagesOnScroll; + /// Whether to show a loading indicator for new messages loading final bool loadingIndicatorForNewMessages; diff --git a/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart b/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart index 04728ef..74b4784 100644 --- a/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart +++ b/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart @@ -352,14 +352,18 @@ class _ChatBody extends HookWidget { var distanceFromBottom = maxScroll - offset; - if (offset <= threshold && !isLoadingOlder.value) { - unawaited(loadOlderMessages()); + if (options.paginationControls.loadOldMessagesOnScroll) { + if (offset <= threshold && !isLoadingOlder.value) { + unawaited(loadOlderMessages()); + } } - if (distanceFromBottom <= threshold && - !isLoadingNewer.value && - !autoScrollEnabled.value) { - unawaited(loadNewerMessages()); + if (options.paginationControls.loadNewMessagesOnScroll) { + if (distanceFromBottom <= threshold && + !isLoadingNewer.value && + !autoScrollEnabled.value) { + unawaited(loadNewerMessages()); + } } if (distanceFromBottom > autoScrollThreshold) {