Norbert515 / dynamic_theme

Dynamically changing your theme without hassle
MIT License
322 stars 68 forks source link

dynamic_theme v2.0 #63

Open TesteurManiak opened 2 years ago

TesteurManiak commented 2 years ago

Hi @Norbert515,

First of all, thank you for your package, it helped me a lot for the first few Flutter projects I've made.

Your package seems to be unmaintained for a bit of time so I took the liberty of adapting your original work to make it fit my needs with the most recent releases of Flutter in one of my recent project. I've changed a bit the base behavior you've created to support ThemeMode instead of Brightness changes so the theme data can be updated with the light, dark or system values.

If you are interested I'd be glad to merge my modifications in your package, but note there is a few breaking changes (this is why I'm talking about a v2.0). You can already check out the code from my repository: https://github.com/TesteurManiak/ygo_collection_manager/blob/main/dynamic_theme/lib/src/dynamic_theme.dart

And here's a sample of how I'm using it in my project:

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return DynamicTheme(
      themedWidgetBuilder: (_, themeMode) {
        return MaterialApp(
          themeMode: themeMode,
          darkTheme: MyThemes.dark,
          theme: MyThemes.light,
          initialRoute: LoadingView.routeName,
          onGenerateRoute: generateRoute,
        );
      },
    );
  }
}

As you can see with the most recent version of Flutter you don't need to change the value of theme depending of the application Brightness anymore, it is the themeMode parameter that will define which of theme or darkTheme should be used.

So if you are interested I'd be glad to merge my code in your repo so everyone can beneficiate from it (also I could be helping solving the remaining opened issues).

Here's the issues that would be solved with this new code:

guillempuche commented 2 years ago

Make a pull request.