next method

Future<void> next()

Invokes _nextContacts and _nextUsers for fetching the next page.

Implementation

Future<void> next() async {
  // Fetch all the [chats] first to prevent them from appearing in other
  // [SearchCategory]s.
  if (_chatService.hasNext.isTrue) {
    if (_chatService.nextLoading.isFalse) {
      searchStatus.value = RxStatus.loadingMore();

      await _chatService.next();
      await Future.delayed(16.milliseconds);

      // Populate [chats] first until there's no more [Chat]s to fetch from
      // [ChatService.paginated], then it is safe to populate other
      // [SearchCategory]s.
      if (_chatService.hasNext.isTrue) {
        _populateChats();
      } else {
        populate();
      }

      if (!hasNext) {
        searchStatus.value = RxStatus.success();
      }
    }
  } else if (query.value.length > 1) {
    await _nextContacts();
    await _nextUsers();
  }
}