flutter navigator.pop()黑屏

这个问题

https://stackoverflow.com/questions/53723294/flutter-navigator-popcontext-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 MaterialAppinstead, 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.

 

简单地说,不要有两个materialapp,因为导航是依赖于这个的,有两个,就会有两个导航

你可能感兴趣的:(flutter)