Sapinder Singh
Sapinder Singh

Reputation: 158

Flutter: How to show splash screen based on theme data saved using shared preferences?

Currently the splash screen is showed according to the device theme and rest of the app according to user selected theme, but I want to show the splash screen according to the selected theme by the user (which I do save in shared preferences).

Upvotes: 2

Views: 266

Answers (2)

Matthew Trent
Matthew Trent

Reputation: 3264

Uh, technically it's possible.

Here's a high-level overview:

You can always show a blank Container() on opening your app, while in the meantime you have your SharedPrefs checking the saved theme/appearance, then, once you have that data, you can show a splash screen where the rest of your prefs then load.

While at first glance this may seem inefficient, the call to SharedPrefs is so fast users literally won't notice that there was a frame of a blank screen before the Splash Screen comes up.


Source: Implemented this for my team's app and it works beautifully.

Upvotes: 0

Dmytro Rostopira
Dmytro Rostopira

Reputation: 11165

It's not possible.

Splash screen is handled by the system, and you app isn't launched yet, so no code to load user preferences could be run.

Upvotes: 3

Related Questions