mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-18 18:33:49 +02:00
feat: add flag to disable new/old message loading on scroll
This commit is contained in:
parent
371ff6c335
commit
5126b8dab7
3 changed files with 22 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue