Skip to content

Load saved theme on start #27

@mliitfall

Description

@mliitfall

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,
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions