flare_splash_screen
flare_splash_screen copied to clipboard
How do I reload the splash screen?
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?
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.
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.
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
Sweet, that did it!
I'm pretty neglectful with key
s myself, I totally get it.
Glad it worked ! I'm keeping this one open to remind me to fix those keys ^^ Thanks !