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

Load saved theme on start #27

Open
mliitfall opened this issue Sep 11, 2019 · 1 comment
Open

Load saved theme on start #27

mliitfall opened this issue Sep 11, 2019 · 1 comment

Comments

@mliitfall
Copy link

mliitfall commented Sep 11, 2019

Hi, love this package.
I don't know how to load saved theme in the first start in MaterialApp?
on data, It going to _loadSavedThemeData and based on SharedPreferences local storage to get String then if case is blue, it will return blueTheme. But what I got is sometimes it could load the theme, sometimes it could not load. Could you help me?

DynamicTheme(
          defaultBrightness: Brightness.light,
          data: (brightness) => _loadSavedThemeData,
          themedWidgetBuilder: (context, theme) {
            return MaterialApp(
              debugShowCheckedModeBanner: false,
//        title: AppLocalizations.of(context).tr('title'),
              theme: theme...
);

_loadSavedThemeData() {
    switch(Pref.localStorage.getString(Strings.themes)){
      case 'blue':
        return CustomTheme.blueTheme;
      case 'green':
        return CustomTheme.greenTheme;
    }
  }

class CustomTheme {
  static final ThemeData blueTheme = ThemeData(
    backgroundColor: Colors.blue,
    accentColor: Colors.blue[800],
    primaryColor: Colors.black,
  );
}
@Norbert515
Copy link
Owner

That seems weird, are you sure your Pref class is working as expected?
Just looked over the code, and this should in fact work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants