add infinite scroll to entries
This commit is contained in:
@@ -18,6 +18,26 @@ class _LegFetchOptions {
|
||||
this.unallocatedOnly = false,
|
||||
this.networkFilter = const [],
|
||||
});
|
||||
|
||||
_LegFetchOptions copyWith({
|
||||
int? limit,
|
||||
String? sortBy,
|
||||
int? sortDirection,
|
||||
String? dateRangeStart,
|
||||
String? dateRangeEnd,
|
||||
bool? unallocatedOnly,
|
||||
List<String>? networkFilter,
|
||||
}) {
|
||||
return _LegFetchOptions(
|
||||
limit: limit ?? this.limit,
|
||||
sortBy: sortBy ?? this.sortBy,
|
||||
sortDirection: sortDirection ?? this.sortDirection,
|
||||
dateRangeStart: dateRangeStart ?? this.dateRangeStart,
|
||||
dateRangeEnd: dateRangeEnd ?? this.dateRangeEnd,
|
||||
unallocatedOnly: unallocatedOnly ?? this.unallocatedOnly,
|
||||
networkFilter: networkFilter ?? this.networkFilter,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DataService extends ChangeNotifier {
|
||||
@@ -397,11 +417,11 @@ class DataService extends ChangeNotifier {
|
||||
List<String> networkFilter = const [],
|
||||
}) async {
|
||||
_isLegsLoading = true;
|
||||
final normalizedNetworks = networkFilter
|
||||
.map((network) => network.trim())
|
||||
.where((network) => network.isNotEmpty)
|
||||
.toList();
|
||||
if (!append) {
|
||||
final normalizedNetworks = networkFilter
|
||||
.map((network) => network.trim())
|
||||
.where((network) => network.isNotEmpty)
|
||||
.toList();
|
||||
_lastLegsFetch = _LegFetchOptions(
|
||||
limit: limit,
|
||||
sortBy: sortBy,
|
||||
@@ -437,6 +457,17 @@ class DataService extends ChangeNotifier {
|
||||
if (json is List) {
|
||||
final newLegs = json.map((e) => Leg.fromJson(e)).toList();
|
||||
_legs = append ? [..._legs, ...newLegs] : newLegs;
|
||||
if (append) {
|
||||
_lastLegsFetch = _lastLegsFetch.copyWith(
|
||||
limit: _legs.length,
|
||||
sortBy: sortBy,
|
||||
sortDirection: sortDirection,
|
||||
dateRangeStart: dateRangeStart,
|
||||
dateRangeEnd: dateRangeEnd,
|
||||
unallocatedOnly: unallocatedOnly,
|
||||
networkFilter: normalizedNetworks,
|
||||
);
|
||||
}
|
||||
// Keep "load more" available as long as the server returns items; hide only on empty.
|
||||
_legsHasMore = newLegs.isNotEmpty;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user