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

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 tests 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
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..30aceaf420175073d776f33c880c16c99d20cb60 100644
--- a/sky/sdk/lib/widgets/icon.dart
+++ b/sky/sdk/lib/widgets/icon.dart
@@ -4,6 +4,8 @@
import '../mojo/asset_bundle.dart';
import 'basic.dart';
+import 'icon_theme.dart';
+import 'theme.dart';
AssetBundle _initIconBundle() {
if (rootBundle != null)
@@ -15,10 +17,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 +54,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())
);
}

Powered by Google App Engine
This is Rietveld 408576698