Skip to content

Commit b951f63

Browse files
changes
1 parent 6b34630 commit b951f63

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/src/controller/chat_controller.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {

lib/src/extensions/extensions.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
22

33
import '../models/data_models/reaction.dart';
44
import '../models/data_models/reply_message.dart';
5+
import '../values/enumeration.dart';
56

67
extension 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+
}

lib/src/values/enumeration.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)