Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Unified Diff: sky/sdk/lib/widgets/icon.dart

Issue 1235443002: Support for icon theming (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix analyzer warning Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/widgets/floating_action_button.dart ('k') | sky/sdk/lib/widgets/menu_item.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/icon.dart
diff --git a/sky/sdk/lib/widgets/icon.dart b/sky/sdk/lib/widgets/icon.dart
index 51117235b4fb02791d814cdfd5275147f2ac131e..bba1b6d300454e983df4bbefa977ee1b68146fcf 100644
--- a/sky/sdk/lib/widgets/icon.dart
+++ b/sky/sdk/lib/widgets/icon.dart
@@ -4,6 +4,37 @@
import '../mojo/asset_bundle.dart';
import 'basic.dart';
+import 'theme.dart';
+import 'widget.dart';
+
+enum IconThemeColor { white, black }
+
+class IconThemeData {
+ const IconThemeData({ this.color });
+ final IconThemeColor color;
+}
+
+class IconTheme extends Inherited {
+
+ IconTheme({
+ String key,
+ this.data,
+ Widget child
+ }) : super(key: key, child: child) {
+ assert(data != null);
+ assert(child != null);
+ }
+
+ final IconThemeData data;
+
+ static IconThemeData of(Component component) {
+ IconTheme result = component.inheritedOfType(IconTheme);
+ return result == null ? null : result.data;
+ }
+
+ bool syncShouldNotify(IconTheme old) => data != old.data;
+
+}
AssetBundle _initIconBundle() {
if (rootBundle != null)
@@ -15,10 +46,29 @@ AssetBundle _initIconBundle() {
final AssetBundle _iconBundle = _initIconBundle();
class Icon extends Component {
- Icon({ String key, this.size, this.type: '' }) : super(key: key);
+ Icon({ String key, this.size, this.type: '', this.color }) : super(key: key);
final int size;
final String type;
+ final IconThemeColor color;
+
+ String get colorSuffix {
+ IconThemeColor iconThemeColor = color;
+ if (iconThemeColor == null) {
+ IconThemeData iconThemeData = IconTheme.of(this);
+ iconThemeColor = iconThemeData == null ? null : iconThemeData.color;
+ }
+ if (iconThemeColor == null) {
+ ThemeBrightness themeBrightness = Theme.of(this).brightness;
+ iconThemeColor = themeBrightness == ThemeBrightness.dark ? IconThemeColor.white : IconThemeColor.black;
+ }
+ switch(iconThemeColor) {
+ case IconThemeColor.white:
+ return "white";
+ case IconThemeColor.black:
+ return "black";
+ }
+ }
Widget build() {
String category = '';
@@ -33,7 +83,7 @@ class Icon extends Component {
String density = 'drawable-xxhdpi';
return new AssetImage(
bundle: _iconBundle,
- name: '${category}/${density}/ic_${subtype}_${size}dp.png',
+ name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png',
size: new Size(size.toDouble(), size.toDouble())
);
}
« no previous file with comments | « sky/sdk/lib/widgets/floating_action_button.dart ('k') | sky/sdk/lib/widgets/menu_item.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698