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

When i want to Navigate to new Screen with naviation.push() 

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

error came.

Issue caused by below code

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Center(
        child: RaisedButton(
          child: Text("About"),
          onPressed: () {
            Navigator.push(context, MaterialPageRoute(builder: (context){
              return About();
            }));
          },
        ),
      ),
    );
  }
}

 

 

To fix the Navigator operation requested with a context that does not include a Navigator error i have modified with below code

I have used Builder Widget and added all my widgets inside Builder widget.

 

 

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (context) => Center(
              child: RaisedButton(
                child: Text("About"),
                onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context){
  return About();
}));
},
              ),
            ),
      ),
    );
  }
}

 


Flutter Questions

Android Questions

Python Questions

Java Questions