ListUicController<T> constructor

ListUicController<T>({
  1. List<T>? items,
  2. required Future<List<T>?> onGetItems(
    1. int
    ),
  3. bool initialLoading = true,
  4. bool allowPagination = true,
})

Implementation

ListUicController({
  List<T>? items,
  required this.onGetItems,
  this.initialLoading = true,
  this.allowPagination = true,
}) {
  _items = ValueNotifier(items ?? <T>[]);
  _page = 1;
  if (_items.value.isEmpty) {
    if (initialLoading) {
      _state = ValueNotifier(_ListUicState.emptyProgress);
      refresh();
    } else {
      _state = ValueNotifier(_ListUicState.emptyData);
    }
  } else {
    _state = ValueNotifier(_ListUicState.data);
  }

  if (allowPagination) {
    _scrollController.addListener(() {
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent) {
        if (_readyForNextPage) {
          _readyForNextPage = false;
          nextPage();
        }
      } else if (_scrollController.position.pixels <=
          _scrollController.position.maxScrollExtent - 10.0) {
        _readyForNextPage = true;
      }
    });
  }
}