Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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(),
},
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading