Navigator operation requested with a context that does not include a Navigator (Flutter)

140

Maybe you are not passing the Scaffold context to a separate widget and using it directly.

Either make a separate Widget for this ListTile or wrap it with a Builder as follow:

Builder(
   builder: (context) => ListTile(
     title: Text('Exercises'),
     onTap: () {
       Navigator.of(context).push(
         MaterialPageRoute(
           builder: (context) => Exercises(),
         ),
       );
     },
   ),
 ),
Share:
140
heyheyhello
Author by

heyheyhello

Updated on December 22, 2022

Comments

  • heyheyhello
    heyheyhello over 1 year

    I want to be able to navigate from Main.dart to Exercises.dart. When I tap on the List Tile in my App Drawer I get the following error:

    Navigator operation requested with a context that does not include a Navigator.

    Main.dart

    exercises.dart

    Entire class Entire class

    What seems to be the problem?

    Thanks

    • heyheyhello
      heyheyhello almost 4 years
      ive also imported exercises.dart to main.dart
    • Aadiyaara
      Aadiyaara almost 4 years
      This has something to do with where the Navigator is called, could u share the entire class?
    • heyheyhello
      heyheyhello almost 4 years
      hi ive added the class as I have it