2

This is my home page code:

routes: {
    '/second' : (context) => addExpence(),
  },

my second-page code is:

FlatButton(
            child: Text("Done".toUpperCase()),
            onPressed: (){
              Navigator.pop(context);
            },
          )

please note that both pages are in different files. Now the problem is that I am getting a black screen when popping from the First Page.

Jamilur Rahman
  • 69
  • 2
  • 12

2 Answers2

2

It's a natural thing to get a black screen when you pop from the first page because the Navigator will be empty. The only reason you're popping the first page is probably to close your app, for which you should use this method.

Mazin Ibrahim
  • 7,433
  • 2
  • 33
  • 40
  • but how will you be able to know that that method should be used to exit the app? override the back button event and check if it is the top screen? – chitgoks Dec 31 '19 at 08:18
  • 2
    @chitgoks for me , if Navigator.of(context).canPop() is true call Navigator.of(context).pop() ,otherwise SystemNavigator.pop() – Lewis Weng Oct 09 '20 at 06:26
0

@Lewis Weng's answer is the correct one that works for me too.

if(Navigator.canPop(context)){
   Navigator.of(context).pop();
}else{
   SystemNavigator.pop();
}
Umair
  • 1,759
  • 6
  • 23
  • 44