Here is my code
return FutureBuilder(
future: dbHelper.abonnements(),
builder: (context,snapshot){
if(snapshot.data==null){
return StartUpScreen();
}else{
final meterId = snapshot.data![0].meterId;
final clientId = snapshot.data![0].clientId;
final abonnement = snapshot.data![0];
final compteur = await MeterAPIManager.getMeter(meterId);
final user = await ClientAPIManager.getUser(clientId);
return HomeScreen(abonnement: abonnement,compteur: compteur,user: user);
}
}
);
Retriving varables compteur and user gives me errors. I cannot add async to my builder.
How can I solve this problem ?
2
Answers
You can use a combination of async and await within a function to perform asynchronous operations before returning the widget tree. However, you need to ensure that the function containing the asynchronous operations returns a widget.
you could do all work in function:
where:
and then