Line data Source code
1 : import 'dart:collection'; 2 : 3 : import 'package:equatable/equatable.dart'; 4 : import 'package:flutter/foundation.dart'; 5 : 6 : /// List of elements with information whether there could be even more elements. 7 : /// 8 : /// [T] - type of list elements. 9 : @immutable 10 : class PagedList<T> extends Equatable { 11 : final List<T> elements; 12 : final bool hasReachedMax; 13 : 14 : /// Creates paged list. 15 : /// 16 : /// [elements] - list of elements, cannot be null or empty, 17 : /// [hasReachedMax] - flag informing if all elements has already been fetched. 18 : /// True if there are more pages, false otherwise. 19 2 : PagedList(List<T> elements, {this.hasReachedMax = false}) 20 : : assert( 21 2 : elements != null && elements.isNotEmpty, 22 : 'Elements cannot be empty', 23 : ), 24 2 : this.elements = UnmodifiableListView(elements); 25 : 26 0 : bool get hasMoreElements => !hasReachedMax; 27 : 28 2 : @override 29 6 : List<Object> get props => [elements, hasReachedMax]; 30 : 31 2 : @override 32 6 : String toString() => '$elements, hasReachedMax: $hasReachedMax'; 33 : }