How to use FutureBuilder with intro slider?

Viewed 272

I'm using the flutter package: https://pub.dev/packages/intro_slider and once the intro has already been viewed the first time the user has logged, I don't want the intro to show on subsequent app opens. There is a visual error where the intro briefly appears before switching to the main app on the subsequent opens, so I tried to use FutureBuilder, but I'm quite inexperienced. Here is where the widget is being built:

@override
  Widget build(BuildContext context) {
        return FutureBuilder(
          future: restore(),
          builder: (BuildContext context, snapshot){
            return new IntroSlider(
              // List slides
              slides: this.slides,

              // Skip button
              renderSkipBtn: this.renderSkipBtn(),
              onSkipPress: this.onSkipPress,
              highlightColorSkipBtn: Color(0xff000000),

              // Next, Done button
              onDonePress: this.onDonePress,
              renderNextBtn: this.renderNextBtn(),
              renderDoneBtn: this.renderDoneBtn(),
              highlightColorDoneBtn: Color(0xff000000),

              // Dot indicator
              colorDot: Colors.white10,
              colorActiveDot: Colors.greenAccent,
              sizeDot: 8.0,
            );
          }
        );
      }
  }

Here is my restore function:

Future<String> restore() async {
    final SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
    setState(() {
      yn = (sharedPrefs.getBool('yn') ?? false);
    });
    if (yn){
      Navigator.pushReplacement(context, new MaterialPageRoute(
          builder: (context) => SplashScreen()
      ));
    }else{
      await sharedPrefs.setBool('yn', true);
    }
  }

And here's my initState if it matters:

void initState() {
    super.initState();
    restore();
    slides.add(
      new Slide(
        title: "Hail",
        styleTitle:
        TextStyle(color: Colors.white, fontSize: 30.0, fontFamily: 'Courier'),
        description: "Allow miles wound place the leave had. To sitting subject no improve studied limited",
        styleDescription:
        TextStyle(color: Colors.white, fontSize: 20.0, fontFamily: 'Mono'),
        pathImage: "assets/totoro.png",
        backgroundColor: Colors.black,
      ),
    );
}

The yn variable is just to check if it is the user's first time opening the app. Thanks in advance!!

0 Answers
Related