dynamic_theme icon indicating copy to clipboard operation
dynamic_theme copied to clipboard

Customizing based on each brightness

Open mohammadne opened this issue 6 years ago • 1 comments

I want to define accentColor , scaffoldBackgroundColor , for each brightness. also I have some textTheme which I want to define for each brightness. but if I write scaffoldBackgroundColor like bellow , it doesn't work:

ThemeData(
                brightness: brightness,
                scaffoldBackgroundColor:
                    Theme.of(context).brightness == Brightness.light
                        ? Colors.black
                        : Colors.white,
               ...
                fontFamily: 'IranYekan',
                textTheme: TextTheme(
                  headline: TextStyle(
                      color: Colors.black54, fontWeight: FontWeight.w700),
                  title: TextStyle(
                      color: Colors.black54, fontWeight: FontWeight.w700),
                  subtitle: TextStyle(fontWeight: FontWeight.w700),
                  body2: TextStyle(fontWeight: FontWeight.w300),
                  display1: TextStyle(fontWeight: FontWeight.w700),
                  display2: TextStyle(fontWeight: FontWeight.w700),
                  display3: TextStyle(fontWeight: FontWeight.w700),
                  display4: TextStyle(fontWeight: FontWeight.w700),
                ),
              ...
              )

it seems that this themeData execute only once, if I use DynamicTheme.of(context).setThemeData(Theme.of(context).copyWith()); also it raised an error because I want to save last theme which user select and its accentColor and ... . also I tried to define darkTheme in materialApp but it doesn't work. if we had possibility to define brightness features , it was so good. but is it possible?

mohammadne avatar Sep 11 '19 11:09 mohammadne

Hey, sorry - I'm not quite sure what the issue is.

DynamicTheme.of(context).setThemeData(Theme.of(context).copyWith());

should work just fine. Also, change Theme.of(context).brightness to brightness as the builder supplies a brightness.

This package automatically saves only the brightness of the shared preferences.

Norbert515 avatar Nov 12 '19 09:11 Norbert515