0 purchases
dynamic theme nullsafe
dynamic_theme_nullsafe #
Dynamically changing your theme without hassle #
This packages manages changing your theme during runtime and persiting that theme.
Include in your project #
dependencies:
dynamic_theme_nullsafe: ^1.0.5
copied to clipboard
run packages get and import it
import 'package:dynamic_theme_nullsafe/dynamic_theme_nullsafe.dart';
copied to clipboard
Usage #
Wrap your material app like this:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicThemeNullsafe(
defaultThemeMode: ThemeMode.light,
loadThemeOnStart: true,
data: (mode) => ThemeData(
primarySwatch: Colors.indigo,
brightness: mode == ThemeMode.dark ? Brightness.dark : Brightness.light,
),
themedWidgetBuilder: (
BuildContext context,
ThemeMode mode,
ThemeData? data,
) {
return MaterialApp(
themeMode: mode,
title: 'Flutter Demo',
theme: data,
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
},
);
}
}
copied to clipboard
Change the theme like this:
void changeBrightness() {
DynamicThemeNullsafe.of(context).toggleThemeMode();
}
void changeColor() {
DynamicThemeNullsafe.of(context).setThemeMode(ThemeMode.dark);
}
copied to clipboard
When changing the ThemeMode with ThemeMode, it is additionally stored in the shared preferences.
Getting Started #
For help getting started with Flutter, view our online documentation.
For help on editing package code, view the documentation.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.