Last active
March 8, 2021 20:01
-
-
Save felix-larsen/b1207bd6c1bdd25a1eae7ae83d6d4197 to your computer and use it in GitHub Desktop.
Custom ThemeData Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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,), | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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