A new Flutter Demo Application for Dynamic Custom Theme
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicThemeWidget(
initCustomColor: CustomTheme.light(),
initThemeData: ThemeData.light(),
initLocale: Locale('vi', 'VN'),
child: Application(),
);
}
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
dynamicTheme = DynamicTheme.of<CustomTheme>(context);
}
Switch(value: dynamicTheme.themeData.brightness == Brightness.light, onChanged: (newValue) {
if (newValue) {
dynamicTheme.changeTheme(ThemeData.light(), CustomTheme.light());
} else {
dynamicTheme.changeTheme(ThemeData.dark(), CustomTheme.dark());
}
})