1

i am trying to use the navigator's popUntil method to exit my app so i was thinking if there was a way to pop all previous pages including the firstPage/route and cause the app to exit at this point. e.g The following code would pop all pages until firstPage which is my base route but how do i pop this page too.

    Navigator.popUntil(context, ModalRoute.withName('/firstPage'));
mtkguy
  • 277
  • 2
  • 14

3 Answers3

2

I finally got it to work by calling

SystemChannels.platform.invokeMethod('SystemNavigator.pop');

just to be clear exit(0); also works but is not best practice and might probably give your ios app some issues when deploying.

mtkguy
  • 277
  • 2
  • 14
0

This should work:

import 'dart:io';`
() {
Navigator.popUntil(context, ModalRoute.withName('/firstPage'));
exit(0);
}

And this could work:

() {
Navigator.popUntil(context, ModalRoute.withName('/firstPage'));
Navigator.pop();
}
Markus Hein
  • 604
  • 7
  • 14
0

if you want to close the app just call exit(0) on the event.

Gopal Awasthi
  • 423
  • 1
  • 6
  • 15