'Flutter - Navigator doesn't return back (Black screen)

I'm new on flutter, I have a Homepage where I have a Drawer menu and body list content.

DRAWER MENU => On tap item list of drawer menu I'm loading a PAGE web URL and on tap BACK it returns to my homepage. So it works very well.

BODY LIST CONTENT => On tap item list it loads the page web URL well BUT when I won't return back to my homepage it returns a black screen :(

Homepage.dart

class HomePage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _HomePage();
  }

}

class _HomePage extends State<HomePage>{

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    var globalContext = context;
    return Scaffold(

      appBar: AppBar(
        title: Text(
            'Benvenuto',
            style: TextStyle(color: Colors.white)
        ),
        backgroundColor: Color(0xFF4035b1),
      ),
      drawer: Drawer(
        child: new Column(
          children: <Widget>[
            new UserAccountsDrawerHeader(
                accountName: Text('VIA ALBERTO POLIO 54'),
                decoration: BoxDecoration(
                    gradient: LinearGradient(
                        colors: [
                          Color(0xFF4268D3),
                          Color(0xFF584CD1)
                        ],
                        begin: FractionalOffset(0.2, 0.0),
                        end: FractionalOffset(1.0, 0.6),
                        stops: [0.0, 0.6],
                        tileMode: TileMode.clamp
                    )
                ),
                accountEmail: Text('ORARI: LUNEDI - VENERDI 9:30 / 19:30'),
                currentAccountPicture: new CircleAvatar(
                  radius: 50.0,
                  backgroundColor: const Color(0xFF778899),
                  backgroundImage: AssetImage("assets/img/icon_logo.jpg"),
                )
            ),
            // This list work well! 
            ListTile(
                leading: new Icon(Icons.arrow_forward_ios),
                title: new Text("TEST"),
                onTap: () {
                  Navigator.of(context).pop();
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (BuildContext context) => Page("title", "www.google.com")));
                }
            )
          ],
        ),
      ),
      // The menu on my body load well the page web url but doesn't return back to my homepage. 
      body: new Column(
          children: <Widget>[
            ListTile(
                leading: new Icon(Icons.arrow_forward_ios),
                title: new Text("TEST"),
                onTap: () {
                  Navigator.of(context).pop();
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (BuildContext context) => Page("title", "www.google.com")));
                }
            )
          ])
    );
  }
}

Page.dart

class Page extends StatelessWidget{

  final String titleText;
  final String urlSource;

  Page(this.titleText, this.urlSource);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new WebviewScaffold(
      url: urlSource,
      appBar: new AppBar(
        title: Text(titleText),
      ),
      withZoom: true,
      withLocalStorage: true,
      hidden: true,
    );
  }
}

main.dart

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: HomePage()
    );
  }
}

Thank you for your help guys!



Solution 1:[1]

You shouldn't be using Navigator.pop() just before Navigator.push().

If replacing the current page with a new one is what you want, you can use Navigator.of(context).pushReplacement().

If you only want to navigate to a new route delete the pop method and only use push

Solution 2:[2]

The real problem here is that when you're using Navigator.pop() you're removing it from the "pages stack". When you're using Navigator.pop() at the Drawer(), the ".pop" function removes the Drawer and keeps the main page.

But at the time you use it with the ListTile(), which is part of the "main body" of the page, you just remove it.

Whatever collapses the main page when pressed, such a Drawer, Dialog or even a Keyboard, will be removed using Navigator.pop(), any other thing that is at the page which implements the "Navigator.pop()" will remove the page instead.

Solution 3:[3]

Navigator.of(context).pop();

this one is popping the screen in the flutter. you can refer this doc as well https://api.flutter.dev/flutter/widgets/Navigator/pop.html your home page doesn't have any stack behind it so when you have written Navigator.of(context).pop(); then it will pop the home page where there is not anything and it always shows the blank screen. when you have tried Navigator.of(context).pop(); in the drawer then it has home page as a stack in the flutter which is the home page in your case and it will pop to the home page and show the blank page.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hassan Saleh
Solution 2 Escobar
Solution 3 Christopher Moore