Instance of 'Future<dynamic>' in Flutter
36,731
Without having your code, it's hard to guess, whats going on.. But you may try to wait for the completion of the future.. so do this:
methOdThatLoadsId().then((id) => print("Id that was loaded: $id"));
or
var id = await methodThatLoadsId();
Good luck :)

Author by
Maryam Omrani
Updated on December 10, 2022Comments
-
Maryam Omrani 17 days
I'm getting an int Id from server which in HTTP request in flutter, it is OK and I want to save this value in an variable , but when i call the returned value i get this error Instance of 'Future' , any suggestion ?? Here is the code
child: RaisedButton(onPressed:() { CurrentPrjId= SaveProject(); print("CurrentPrjId Is saved CurrentPrjId :::::::: " ); print(CurrentPrjId); Navigator.of(context).pushReplacementNamed('/AllUSerStories'); } //Save Project Future SaveProject() async { //SaveProjectResult has the id of the current created project which i need that for its user stories var SaveProjectResult = await GetPostProjects().createProject(_ProjectnameController.text, _CustomernameController.text, _dropNewItem, _dropNewItem2, _StartDateController.text, _EndDateController.text,); print(":::::::::::::::::::::::::::::::The Project Is Created And Here Its ID In SaveProject:::::::::"); print(SaveProjectResult); return SaveProjectResult;
}
-
Sami Kanafani over 3 yearsshow your code please
-
Maryam Omrani over 3 yearshi i added the code
-
-
Maryam Omrani over 3 yearsi used your first solution but still have the same problem AS : Instance of 'Future'
-
Kamlesh about 2 yearshow can we use await in initState function? Thanks.
-
ehhc about 2 years@Kamlesh as far as i know, that's not possible at all. Nontheless, there are several ways on how you can work with async-tasks in initState. See stackoverflow.com/a/51901192/11266880 for one solution