File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -153,9 +153,12 @@ base class ChatController {
153153 /// [direction] is used to determine whether to load previous or next data.
154154 void loadMoreData (
155155 List <Message > messageList, {
156+ GroupedListOrder groupedListOrder = GroupedListOrder .asc,
156157 ChatPaginationDirection direction = ChatPaginationDirection .previous,
157158 }) {
158- if (direction.isPrevious) {
159+ final newDirection = groupedListOrder.isAsc ? direction : direction.toggle;
160+
161+ if (newDirection.isPrevious) {
159162 // Passed 0 index as we need to add data before first data
160163 initialMessageList.insertAll (0 , messageList);
161164 } else {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
22
33import '../models/data_models/reaction.dart' ;
44import '../models/data_models/reply_message.dart' ;
5+ import '../values/enumeration.dart' ;
56
67extension TargetPlatformExtension on TargetPlatform {
78 bool get isAndroid => this == TargetPlatform .android;
@@ -70,3 +71,16 @@ extension ListExtension<T> on List<T> {
7071 return mapList;
7172 }
7273}
74+
75+ extension ChatPaginationDirectionExtension on ChatPaginationDirection {
76+ /// Returns the opposite direction of the current pagination direction.
77+ ///
78+ /// For example, if the current direction is [ChatPaginationDirection.previous] ,
79+ /// it will return [ChatPaginationDirection.next] , and vice versa.
80+ ChatPaginationDirection get toggle {
81+ return switch (this ) {
82+ ChatPaginationDirection .previous => ChatPaginationDirection .next,
83+ ChatPaginationDirection .next => ChatPaginationDirection .previous,
84+ };
85+ }
86+ }
Original file line number Diff line number Diff line change @@ -180,3 +180,12 @@ enum ChatPaginationDirection {
180180
181181 bool get isNext => this == next;
182182}
183+
184+ enum GroupedListOrder {
185+ asc,
186+ desc;
187+
188+ bool get isAsc => this == asc;
189+
190+ bool get isDesc => this == desc;
191+ }
You can’t perform that action at this time.
0 commit comments