Skip to content

Instantly share code, notes, and snippets.

@felix-larsen
Last active March 8, 2021 20:01
Show Gist options
  • Save felix-larsen/b1207bd6c1bdd25a1eae7ae83d6d4197 to your computer and use it in GitHub Desktop.
Save felix-larsen/b1207bd6c1bdd25a1eae7ae83d6d4197 to your computer and use it in GitHub Desktop.
Custom ThemeData Flutter
@override
Widget build(BuildContext context) {
final Brightness platformBrightness = Theme.of(context).brightness;
final bool darkTheme = platformBrightness == Brightness.dark;
return CustomAppTheme(
customAppTheme:
darkTheme ? CustomAppThemeData.dark : CustomAppThemeData.light,
child: Icon(Icons.add, color: CustomAppTheme.of(context).addColor,),
);
}
import 'package:calendarflutter/style/custom_app_theme_data.dart';
import 'package:flutter/material.dart';
class CustomAppTheme extends InheritedWidget {
CustomAppTheme({
Key key,
@required Widget child,
this.customAppTheme,
}) : super(key: key, child: child);
final CustomAppThemeData customAppTheme;
static CustomAppThemeData of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<CustomAppTheme>()
.customAppTheme;
}
@override
bool updateShouldNotify(CustomAppTheme oldWidget) =>
customAppTheme != oldWidget.customAppTheme;
}
import 'package:flutter/material.dart';
class CustomAppThemeData {
final Color plusColor;
const CustomAppThemeData({
@required this.plusColor,
});
static CustomAppThemeData get dark {
return CustomAppThemeData(
plusColor: Colors.red,
);
}
static CustomAppThemeData get light {
return CustomAppThemeData(
plusColor: Colors.green,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment