0
votes

I am trying to launch a 'How to Use' screen if the app launches for the first time using a FutureBuilder().

isFisrtTime() returns true if the app is launched for the first time.

Here is the FutureBuilder code:

body: FutureBuilder(
    future: isFirstTime(),
    initialData: Container(),
    builder: (context, snapshot){

      if(snapshot.data == true){

        Navigator.pushNamed(context, '/howtouse');
        return (currentScreen == 'Home')
            ? HomeBody()
            : CBook(changeScreen: changeCurrentScreen);

      }
      else {

        return (currentScreen == 'Home')
            ? HomeBody()
            : CBook(changeScreen: changeCurrentScreen);
      }

    },
  ),

Please Help

1

1 Answers

1
votes

You can't push a new Route during build. Move the logic to your initState instead.

@override
void initState() {
  isFirstTime().then((data) {
    if(data) {
      Navigator.pushNamed(context, '/howtouse');
    }
  }
  super.initState();
}