Because of dart event loop, first of all, completes a sync code, in your case it is:
Navigator.of(context).pop()
Then, it completes a future in completed order, which means, faster response – faster completion.
To make your async code (futures) complete in order like sync, you should pass await keyword before futures, for example, it works like this:
await auth.UpdateData('state', 'offline'); // - completes first
await _signout(context); // - second
Navigator.of(context).pop; // - third
If you’ll not use await keyword, order will look like this:
auth.UpdateData('state', 'offline'); // - query send and wait for response
_signout(context); // - query send and wait for response (logout is usually faster than setting data, that means your user signout first, then - user update data)
Navigator.of(context).pop; // - completes first
2
Answers
solution 1:
solution 2:
put await before auth.updatData
Because of dart event loop, first of all, completes a sync code, in your case it is:
Then, it completes a future in completed order, which means, faster response – faster completion.
To make your async code (futures) complete in order like sync, you should pass await keyword before futures, for example, it works like this:
If you’ll not use await keyword, order will look like this: