Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I reload the splash screen? #25

Open
rubenvereecken opened this issue Aug 17, 2020 · 5 comments
Open

How do I reload the splash screen? #25

rubenvereecken opened this issue Aug 17, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@rubenvereecken
Copy link

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?

@jaumard
Copy link
Owner

jaumard commented Aug 17, 2020

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.

@rubenvereecken
Copy link
Author

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.

@jaumard
Copy link
Owner

jaumard commented Aug 17, 2020

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

@rubenvereecken
Copy link
Author

Sweet, that did it!

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

@jaumard
Copy link
Owner

jaumard commented Aug 17, 2020

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

@jaumard jaumard added the bug Something isn't working label Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants