mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-14 20:22:15 -04:00
pagination
This commit is contained in:
parent
5473bd2ee4
commit
2c38fc6489
22 changed files with 1071 additions and 545 deletions
27
lib/chat/models/window_state.dart
Normal file
27
lib/chat/models/window_state.dart
Normal file
|
@ -0,0 +1,27 @@
|
|||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'window_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class WindowState<T> with _$WindowState<T> {
|
||||
const factory WindowState({
|
||||
// List of objects in the window
|
||||
required IList<T> window,
|
||||
// Total number of objects (windowTail max)
|
||||
required int length,
|
||||
// One past the end of the last element
|
||||
required int windowTail,
|
||||
// The total number of elements to try to keep in the window
|
||||
required int windowCount,
|
||||
// If we should have the tail following the array
|
||||
required bool follow,
|
||||
}) = _WindowState;
|
||||
}
|
||||
|
||||
extension WindowStateExt<T> on WindowState<T> {
|
||||
int get windowEnd => (length == 0) ? -1 : (windowTail - 1) % length;
|
||||
int get windowStart =>
|
||||
(length == 0) ? 0 : (windowTail - window.length) % length;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue