Home > Mobile >  How to call functions after previous function is completed in Flutter?
How to call functions after previous function is completed in Flutter?

Time:01-28

onPressed: () => {
     popUpForGroup("Add Group", null, context),
     print("pop up closed"),
     refreshPage(),
},

Here all three functions run at the same time. I want to execute the refreshPage() function only when the popUpForGroup() execution ends. popUpForGroup() is a function from another file, it displays a Dialogue box for adding a group to the database, and I wanted to refresh my current file( where I call the onpressed function)

CodePudding user response:

Transform your popUpForGroup to async function like this.

Future<void> popUpForGroup({...}) {...}

After that and inside your onPressed Function you can write this:

onPressed: () async => {
     await popUpForGroup("Add Group", null, context),
     print("pop up closed"),
     refreshPage(),
},
  •  Tags:  
  • Related