This packages manages changing your theme during runtime and persiting that theme.
I wrote a medium post about this, check it out here!
dependencies:
dynamic_theme:
git:
url: git://github.com/Norbert515/dynamic_theme.git
run packages get and import it
import 'package:dynamic_theme/dynamic_theme.dart';
if you want the dialog:
import 'package:dynamic_theme/theme_switcher_widgets.dart';
If you are not able to import it, restart your IDE see: flutter/flutter#17016
Wrap your material app like this:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new DynamicTheme(
defaultBrightness: Brightness.light,
data: (brightness) => new ThemeData(
primarySwatch: Colors.indigo,
brightness: brightness,
),
themedWidgetBuilder: (context, theme) {
return new MaterialApp(
title: 'Flutter Demo',
theme: theme,
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
);
}
}
Change the theme like this:
void changeBrightness() {
DynamicTheme.of(context).setBrightness(Theme.of(context).brightness == Brightness.dark? Brightness.light: Brightness.dark);
}
void changeColor() {
DynamicTheme.of(context).setThemeData(new ThemeData(
primaryColor: Theme.of(context).primaryColor == Colors.indigo? Colors.red: Colors.indigo
));
}
For help getting started with Flutter, view our online documentation.
For help on editing package code, view the documentation.