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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 for me , if Navigator.of(context).canPop() is true call Navigator.of(context).pop() ,otherwise SystemNavigator.pop()
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();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.