Flutter Navigator.pop(context) returning a black screen

This can happen if your MoviesPage has another MaterialApp widget. Most of the time you want to use Scaffold as a top widget for a new page/screen, but if you accidentally use MaterialApp instead, nothing warns you.

What happens, is that MaterialApp creates a new Navigator, so if you switch from one page with MaterialApp to another, you now have two Navigators in the widget tree.

The call Navigator.of(context) looks for the closest Navigator, so it'll use the one, newly created in your MoviesPage. As the history of your route transitions is stored in a first Navigator, this one can't pop back – it has empty route history.

Hence, the black screen.

Long story short, to fix this, just use Scaffold as a top widget instead of MaterialApp in all nested screens.


I had similar issues while poping back views, the way I fixed was instead of Navigator.of(context).pop(); I use Navigator.of(context).maybePop();.

No more black screens after that.


Just add optionally param rootNavigator: true: Sample:

Navigator.of(context, rootNavigator: true).pop(context);

Edit: In some cases, this solution may not resolve your issue. Please make sure that there is only one MaterialApp widget in your app for all Pages.


I resolve it using this code:

Navigator.pushReplacementNamed(context, '/route');