Jamilur Rahman
Jamilur Rahman

Reputation: 69

Getting a black screen when navigating between two pages in flutter

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.

Upvotes: 2

Views: 4214

Answers (2)

Umair
Umair

Reputation: 1877

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

if(Navigator.canPop(context)){
   Navigator.of(context).pop();
}else{
   SystemNavigator.pop();
}

Upvotes: 0

Mazin Ibrahim
Mazin Ibrahim

Reputation: 7889

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.

Upvotes: 2

Related Questions