Flutter get User is not working

void getUsers(AmityUserSortOption amityUserSortOption) {
    try {
      /// Checking make sure user is loggedIn
      bool ids = AmityCoreClient.isUserLoggedIn();
      print(ids.toString());
      _amityUsersController = PagingController(
        pageFuture: (token) => AmityCoreClient.newUserRepository()
            .getUsers()
            .sortBy(amityUserSortOption)
            .getPagingData(token: token, limit: 20),
        pageSize: 20,
      )..addListener(
          () {
            if (_amityUsersController.error == null) {
              //handle _amityUsersController, we suggest to clear the previous items
              //and add with the latest _controller.loadedItems
              _amityUsers.clear();
              _amityUsers.addAll(_amityUsersController.loadedItems);
              print(_amityUsers.length.toString());
              //update widgets
            } else {
              //error on pagination controller
              //update widgets
            }
          },
        );
    } catch (e) {
      print(e.toString());
    }
  }

Hi @AmSK

This issue occurs because _amityUsersController needs to be trigger once. Please find the code below to trigger the first fetch:

 WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _amityUsersController.fetchNextPage();
    });

Anything else please don’t hesitate to let us know.
Amity Support