rydmike / flex_color_scheme

A Flutter package to make and use beautiful color scheme based themes.
Other
887 stars 100 forks source link

How to change the theme color through the button #202

Closed laterdayi closed 8 months ago

laterdayi commented 8 months ago

How to change the theme color through the button, I want to provide a list of topics that can be clicked,And you can cache it

rydmike commented 8 months ago

Hi,

Can you elaborate a bit? Explain in more detail what you want to do please.

If it is of any help, I just answered the question about making a button type black, via theming, here: https://github.com/rydmike/flex_color_scheme/discussions/201#discussioncomment-7317719

But not sure if that is what you are asking about.

If the question is about how to make an app that uses a user customizable theme, so that user via choices can changes different aspects of the app theme and thus how the app looks, interactively. Well, in that case I recommend going through the documentation tutorials, starting from example 2 to example 5. Where example 5 is the entire Themes Playground app.

Basically, FlexColorScheme just returns a very fancy ThemeData object, and you can use any UI controls and values selected from them, as input to the FlexColorScheme API that then returns new ThemeData whenever the input is modified. You need a mechanism that triggers rebuild of the app when the theme changes. Your preferred state management solution, be it Provider, Riverpod, FlutterBloc, MobX, Redux or something else, can do that for you. Or you can just use a simple Flutter ChangeNotifier and ListenableBuilder, like the examples do to avoid the eternal Flutter state management debate in the examples.

laterdayi commented 8 months ago

Ok, got it. I'm currently using getx, which I'm trying to use to change the theme