Linked Questions

Popular Questions

Flutter: Navigation issue

Asked by At

I'm not able to navigate screen showing error 'Navigator operation requested with a context that does not include a Navigator, I have tried many solutions where navigator is used in Builder with stateless widgets but here navigation is done automatically after a few seconds in override method in intiSate. my aim is to navigate the screen after a few seconds.

class Splash extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return testWidget;
      }
    }

Widget testWidget = new MediaQuery(
    data: new MediaQueryData(),
    child: new MaterialApp( title: 'xxxxxxxxxxxxx',
      home: SplashScreen(),
      debugShowCheckedModeBanner: false,
      routes: <String, WidgetBuilder>{
        '/login': (BuildContext context) => new Login(),
      },
    )

);

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => new _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen>  {
  @override
  Future initState ()  {
    super.initState();
   new Future.delayed(
        const Duration(seconds: 2), () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => Login()),
        ));
  }
  @override
  Widget build(BuildContext context) {

    return(Scaffold(
      body: Container(
        height: double.infinity,
        width: double.infinity,
        child: Image.asset('assets/images/crop.jpg',fit:BoxFit.fill),
      ),
    ));
    //build
  }
}

Showing Error

Navigator operation requested with a context that does not include a Navigator. The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.

Related Questions