dynamic_theme_mode 1.0.0 copy "dynamic_theme_mode: ^1.0.0" to clipboard
dynamic_theme_mode: ^1.0.0 copied to clipboard

A Flutter widget that allows theme mode changing during runtime.

dynamic_theme_mode #

version All Contributors

A Flutter widget that allows theme mode changing during runtime.

Installation #

Add this to your pubspec.yaml:

dependencies:
  dynamic_theme_mode: ^1.0.0

Usage #

  • Import the DynamicThemeMode widget, wrap MaterialApp with it and pass an initial ThemeMode value.
import 'package:dynamic_theme_mode/dynamic_theme_mode.dart';

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    return DynamicThemeMode(
      initialThemeMode: ThemeMode.system,
      builder: (BuildContext context, ThemeMode themeMode) {
        return MaterialApp(
          theme: ThemeData(
            brightness: Brightness.light,
            primarySwatch: Colors.orange,
          ),
          darkTheme: ThemeData(
            brightness: Brightness.dark,
            primarySwatch: Colors.yellow,
          ),
          // Here we use the themeMode dynamic value!
          themeMode: themeMode,
          home: ExampleHome(),
        );
      },
    );
  }
}
  • Change the themeMode to use with:
DynamicThemeMode.managerOf(context)?.useDarkMode();
// Or
DynamicThemeMode.managerOf(context)?.setThemeMode(ThemeMode.light);
  • Get the current themeMode value with:
DynamicThemeMode.managerOf(context)?.themeMode;

The example folder has a complete example!

API #

builder #

Type: Widget Function(BuildContext context, ThemeMode themeMode).

Method that runs to rebuild the tree when themeMode changes.

manager #

Type: ThemeModeManager.

Holds a ThemeMode value and notifies when it changes, also, it has the methods that changes the themeMode.

Contributors ✨ #

Thanks goes to these wonderful people (emoji key):


Carlos Schwarz

💻 🎨 💡 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

License #

MIT © Carlos Schwarz

4
likes
130
pub points
47%
popularity

Publisher

unverified uploader

A Flutter widget that allows theme mode changing during runtime.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on dynamic_theme_mode