flare_splash_screen icon indicating copy to clipboard operation
flare_splash_screen copied to clipboard

How do I reload the splash screen?

Open rubenvereecken opened this issue 4 years ago • 5 comments

I've got the splash screen wrapped in a StatelessWidget. The idea is that if something really bad fails, a dialog pops up and the user can confirm another attempt. At which point the loading screen starts anew, running the until function which hopefully succeeds this time.

We do our state keeping with streams. I tried to get the SplashScreen to re-load using a StreamBuilder but somehow.. it won't. I can get the re-build to run, but I can't get the splash screen to run again or any of its callback functions.

Here is the relevant snippet:

                StreamBuilder<bool>(
                    stream: Provider.of<StartupScreenBloc>(context).retryStream,
                    builder: (context, snapshot) {
                      print(snapshot.data);
                      return SplashScreen.callback(
//                        key: UniqueKey(),
                        backgroundColor: Colors.white,
                        name: bloc.flare,
                        loopAnimation: 'go',
                        until: bloc.startup,
                        onError: (err, stack) => bloc.onError(context, err),
                        onSuccess: bloc.onSuccess,
                      );
                    })));

I'm probably missing something fundamental about state keeping with Flutter widgets. What's the best way to re-load the splash screen without re-routing or anything hacky?

rubenvereecken avatar Aug 17 '20 15:08 rubenvereecken

Hum that a use case I never had or encounter ^^ there is no built in way to "restart" a splash screen (as normally they just play once and that's it). But to do that if you uncomment key: UniqueKey(), it should work right ? because at each rebuild it will recreate a splash screen from scratch and by doing so re run the callback.

jaumard avatar Aug 17 '20 15:08 jaumard

That's what I thought! So I do understand a bit about StatefulWidgets. Well.. it didn't work. And I made sure a unique key was used the second time. Hmm maybe the key isn't passed properly. We don't use StatefulWidgets often, but perhaps I could try a fork that refreshes a refresh by using setState inside SplashScreen?

As to it being a weird use case, I agree. We're rolling out a version of the app without persistent storage so without network the app is stuck on the loading screen.

rubenvereecken avatar Aug 17 '20 15:08 rubenvereecken

By looking at the code you're right the Key is not passed for named constructors... My bad... you can try using the default constructor SplashScreen(...), let me know if it works like that ! I'll try to push a fix when I have time for the other constructors

jaumard avatar Aug 17 '20 15:08 jaumard

Sweet, that did it!

I'm pretty neglectful with keys myself, I totally get it.

rubenvereecken avatar Aug 17 '20 15:08 rubenvereecken

Glad it worked ! I'm keeping this one open to remind me to fix those keys ^^ Thanks !

jaumard avatar Aug 17 '20 15:08 jaumard