dynamic_theme
dynamic_theme copied to clipboard
Customizing based on each brightness
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?
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.