Instance of 'Future<dynamic>' in Flutter


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"));


var id = await methodThatLoadsId();

Good luck :)

Maryam Omrani
Author by

Maryam Omrani

Updated on December 10, 2022


  • Maryam Omrani
    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 :::::::: " );
    //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:::::::::");
    return SaveProjectResult;


    • Sami Kanafani
      Sami Kanafani over 3 years
      show your code please
    • Maryam Omrani
      Maryam Omrani over 3 years
      hi i added the code
  • Maryam Omrani
    Maryam Omrani over 3 years
    i used your first solution but still have the same problem AS : Instance of 'Future'
  • Kamlesh
    Kamlesh about 2 years
    how can we use await in initState function? Thanks.
  • ehhc
    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 for one solution