flutter -> error to open new route : type 'Future<dynamic>' is not a subtype of type 'Widget'

I have a simple test who open new page after 4000ms from init. But I have this UI error The

following _TypeError was thrown building WithPages(dirty, dependencies: [MediaQuery], state: _WithPages#6c08e):
type 'Future<dynamic>' is not a subtype of type 'Widget'

Here is my code

  @override
  void initState() {

    Future.delayed(const Duration(milliseconds: 4000), () {
      load_first_launch_start();
    });
    super.initState();


  }

  load_first_launch_start() async {

    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {

      first_launch = prefs.getInt('first_launch')??0;
      if(first_launch>=1){
        Navigator.pushAndRemoveUntil(context,   MaterialPageRoute(
          builder: (context) => DrawerPage(),
        ), (e) => false);

      }else{
        
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => WithPages(),
          ), //MaterialPageRoute
        );
      }
    });

  }

>Solution :

the error says WithPages() not a widget or doesn’t return widget

Leave a Reply