'Flutter - Api call receives data but shows null on ui

I have a screen with Getx controller. On init i'm making an api call and assings the result to varible.

AccountModel? _currentAccount; // variable storing received data.

After Api call the response is stored in _currentAccount;

    _getUserDetails() async {
      else {
      try {
        final request = UserRequest(user: user);
        final response =
        await getUserDetails(request: request);
        _currentAccount = response.getAccounts().first; // assigns response value to this variable;
    } catch(e) {
      print(e);
}


oninit() {
  _getUserDetails();
}

On ui i have this widget, which I'm passing the controller to it.

  CurrentPlan(
  controller: controller, // passing the controller to this widget. using the passed controller updates the needed fields in this widget
  ),

The response is stored in this variable. How ever if i'm using this variable on ui im only getting null. The value of this varible is not updating in ui, whats causing this? How can i resolve this?

enter image description here



Solution 1:[1]

Use Future builder. I suspect your UI gets build before you actually receive the data

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yunus Kulyyev