dynamic_theme_mode

Creator: coderz1093

Last updated:

0 purchases

dynamic_theme_mode Image
dynamic_theme_mode Images
Add to Cart

Description:

dynamic theme mode

dynamic_theme_mode #




A Flutter widget that allows theme mode changing during runtime.
Installation #
Add this to your pubspec.yaml:
dependencies:
dynamic_theme_mode: ^1.0.0
copied to clipboard
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(),
);
},
);
}
}
copied to clipboard

Change the themeMode to use with:

DynamicThemeMode.managerOf(context)?.useDarkMode();
// Or
DynamicThemeMode.managerOf(context)?.setThemeMode(ThemeMode.light);
copied to clipboard

Get the current themeMode value with:

DynamicThemeMode.managerOf(context)?.themeMode;
copied to clipboard
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

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.