refresh method

Future<void> refresh()

Implementation

Future<void> refresh() async {
  // Show progress view
  if (_state.value == _ListUicState.emptyData ||
      _state.value == _ListUicState.emptyError) {
    _state.value = _ListUicState.emptyProgress;
  } else if (_state.value != _ListUicState.emptyProgress) {
    _state.value = _ListUicState.progress;
  }
  // Load first page of the data
  _page = 1;
  await _loadItems(_page)
      // Show data
      .then((result) {
    _items.value = result;
    if (_items.value.isEmpty) {
      _state.value = _ListUicState.emptyData;
    } else {
      _state.value = _ListUicState.data;
    }
  })
      // Show error
      .catchError((error) {
    if (_state.value == _ListUicState.emptyProgress) {
      _state.value = _ListUicState.emptyError;
    } else {
      _state.value = _ListUicState.error;
    }
  });
}