Merge pull request #1344 from abarth/icon_color
Simplify colorizing icons
This commit is contained in:
commit
4357d08714
@ -230,7 +230,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
return new ToolBar(
|
return new ToolBar(
|
||||||
left: new IconButton(
|
left: new IconButton(
|
||||||
icon: 'navigation/arrow_back',
|
icon: 'navigation/arrow_back',
|
||||||
colorFilter: new ColorFilter.mode(Theme.of(context).accentColor, ui.TransferMode.srcATop),
|
color: Theme.of(context).accentColor,
|
||||||
onPressed: _handleSearchEnd,
|
onPressed: _handleSearchEnd,
|
||||||
tooltip: 'Back'
|
tooltip: 'Back'
|
||||||
),
|
),
|
||||||
|
@ -19,9 +19,6 @@ const TextStyle _kLabelStyle = const TextStyle(
|
|||||||
textBaseline: TextBaseline.alphabetic
|
textBaseline: TextBaseline.alphabetic
|
||||||
);
|
);
|
||||||
|
|
||||||
final ColorFilter _kIconColorFilter = new ColorFilter.mode(
|
|
||||||
Colors.black54, TransferMode.dstIn);
|
|
||||||
|
|
||||||
class Chip extends StatelessComponent {
|
class Chip extends StatelessComponent {
|
||||||
const Chip({
|
const Chip({
|
||||||
Key key,
|
Key key,
|
||||||
@ -66,7 +63,7 @@ class Chip extends StatelessComponent {
|
|||||||
child: new Icon(
|
child: new Icon(
|
||||||
icon: 'navigation/cancel',
|
icon: 'navigation/cancel',
|
||||||
size: IconSize.s18,
|
size: IconSize.s18,
|
||||||
colorFilter: _kIconColorFilter
|
color: Colors.black54
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
@ -23,13 +23,13 @@ class DrawerItem extends StatelessComponent {
|
|||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
final bool selected;
|
final bool selected;
|
||||||
|
|
||||||
ColorFilter _getIconColorFilter(ThemeData themeData) {
|
Color _getIconColor(ThemeData themeData) {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
if (themeData.brightness == ThemeBrightness.dark)
|
if (themeData.brightness == ThemeBrightness.dark)
|
||||||
return new ColorFilter.mode(themeData.accentColor, TransferMode.srcATop);
|
return themeData.accentColor;
|
||||||
return new ColorFilter.mode(themeData.primaryColor, TransferMode.srcATop);
|
return themeData.primaryColor;
|
||||||
}
|
}
|
||||||
return new ColorFilter.mode(Colors.black45, TransferMode.dstIn);
|
return Colors.black45;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyle _getTextStyle(ThemeData themeData) {
|
TextStyle _getTextStyle(ThemeData themeData) {
|
||||||
@ -53,7 +53,7 @@ class DrawerItem extends StatelessComponent {
|
|||||||
padding: const EdgeDims.symmetric(horizontal: 16.0),
|
padding: const EdgeDims.symmetric(horizontal: 16.0),
|
||||||
child: new Icon(
|
child: new Icon(
|
||||||
icon: icon,
|
icon: icon,
|
||||||
colorFilter: _getIconColorFilter(themeData)
|
color: _getIconColor(themeData)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -27,8 +27,8 @@ class Icon extends StatelessComponent {
|
|||||||
Key key,
|
Key key,
|
||||||
this.size: IconSize.s24,
|
this.size: IconSize.s24,
|
||||||
this.icon: '',
|
this.icon: '',
|
||||||
this.color,
|
this.colorTheme,
|
||||||
this.colorFilter
|
this.color
|
||||||
}) : super(key: key) {
|
}) : super(key: key) {
|
||||||
assert(size != null);
|
assert(size != null);
|
||||||
assert(icon != null);
|
assert(icon != null);
|
||||||
@ -36,11 +36,11 @@ class Icon extends StatelessComponent {
|
|||||||
|
|
||||||
final IconSize size;
|
final IconSize size;
|
||||||
final String icon;
|
final String icon;
|
||||||
final IconThemeColor color;
|
final IconThemeColor colorTheme;
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
|
|
||||||
String _getColorSuffix(BuildContext context) {
|
String _getColorSuffix(BuildContext context) {
|
||||||
IconThemeColor iconThemeColor = color;
|
IconThemeColor iconThemeColor = colorTheme;
|
||||||
if (iconThemeColor == null) {
|
if (iconThemeColor == null) {
|
||||||
IconThemeData iconThemeData = IconTheme.of(context);
|
IconThemeData iconThemeData = IconTheme.of(context);
|
||||||
iconThemeColor = iconThemeData == null ? null : iconThemeData.color;
|
iconThemeColor = iconThemeData == null ? null : iconThemeData.color;
|
||||||
@ -74,7 +74,7 @@ class Icon extends StatelessComponent {
|
|||||||
name: '$category/$density/ic_${subtype}_${colorSuffix}_${iconSize}dp.png',
|
name: '$category/$density/ic_${subtype}_${colorSuffix}_${iconSize}dp.png',
|
||||||
width: iconSize.toDouble(),
|
width: iconSize.toDouble(),
|
||||||
height: iconSize.toDouble(),
|
height: iconSize.toDouble(),
|
||||||
colorFilter: colorFilter
|
color: color
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,15 +13,15 @@ class IconButton extends StatelessComponent {
|
|||||||
const IconButton({
|
const IconButton({
|
||||||
Key key,
|
Key key,
|
||||||
this.icon,
|
this.icon,
|
||||||
|
this.colorTheme,
|
||||||
this.color,
|
this.color,
|
||||||
this.colorFilter,
|
|
||||||
this.onPressed,
|
this.onPressed,
|
||||||
this.tooltip
|
this.tooltip
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final String icon;
|
final String icon;
|
||||||
final IconThemeColor color;
|
final IconThemeColor colorTheme;
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
final String tooltip;
|
final String tooltip;
|
||||||
|
|
||||||
@ -32,8 +32,8 @@ class IconButton extends StatelessComponent {
|
|||||||
padding: const EdgeDims.all(8.0),
|
padding: const EdgeDims.all(8.0),
|
||||||
child: new Icon(
|
child: new Icon(
|
||||||
icon: icon,
|
icon: icon,
|
||||||
color: color,
|
colorTheme: colorTheme,
|
||||||
colorFilter: colorFilter
|
color: color
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -51,8 +51,8 @@ class IconButton extends StatelessComponent {
|
|||||||
description.add('$icon');
|
description.add('$icon');
|
||||||
if (onPressed == null)
|
if (onPressed == null)
|
||||||
description.add('disabled');
|
description.add('disabled');
|
||||||
if (color != null)
|
if (colorTheme != null)
|
||||||
description.add('$color');
|
description.add('$colorTheme');
|
||||||
if (tooltip != null)
|
if (tooltip != null)
|
||||||
description.add('tooltip: "$tooltip"');
|
description.add('tooltip: "$tooltip"');
|
||||||
}
|
}
|
||||||
|
@ -319,8 +319,7 @@ class _Tab extends StatelessComponent {
|
|||||||
|
|
||||||
Widget _buildLabelIcon() {
|
Widget _buildLabelIcon() {
|
||||||
assert(label.icon != null);
|
assert(label.icon != null);
|
||||||
ColorFilter filter = new ColorFilter.mode(color, TransferMode.srcATop);
|
return new Icon(icon: label.icon, color: color);
|
||||||
return new Icon(icon: label.icon, colorFilter: filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -117,7 +117,7 @@ class _TwoLevelSublistState extends State<TwoLevelSublist> {
|
|||||||
turns: _iconTurns,
|
turns: _iconTurns,
|
||||||
child: new Icon(
|
child: new Icon(
|
||||||
icon: 'navigation/expand_more',
|
icon: 'navigation/expand_more',
|
||||||
colorFilter: new ColorFilter.mode(_iconColor.evaluate(_easeInAnimation), TransferMode.srcATop)
|
color: _iconColor.evaluate(_easeInAnimation)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
@ -22,7 +22,7 @@ class RenderImage extends RenderBox {
|
|||||||
ui.Image image,
|
ui.Image image,
|
||||||
double width,
|
double width,
|
||||||
double height,
|
double height,
|
||||||
ColorFilter colorFilter,
|
Color color,
|
||||||
ImageFit fit,
|
ImageFit fit,
|
||||||
FractionalOffset alignment,
|
FractionalOffset alignment,
|
||||||
ImageRepeat repeat: ImageRepeat.noRepeat,
|
ImageRepeat repeat: ImageRepeat.noRepeat,
|
||||||
@ -30,11 +30,13 @@ class RenderImage extends RenderBox {
|
|||||||
}) : _image = image,
|
}) : _image = image,
|
||||||
_width = width,
|
_width = width,
|
||||||
_height = height,
|
_height = height,
|
||||||
_colorFilter = colorFilter,
|
_color = color,
|
||||||
_fit = fit,
|
_fit = fit,
|
||||||
_alignment = alignment,
|
_alignment = alignment,
|
||||||
_repeat = repeat,
|
_repeat = repeat,
|
||||||
_centerSlice = centerSlice;
|
_centerSlice = centerSlice {
|
||||||
|
_updateColorFilter();
|
||||||
|
}
|
||||||
|
|
||||||
/// The image to display.
|
/// The image to display.
|
||||||
ui.Image get image => _image;
|
ui.Image get image => _image;
|
||||||
@ -74,13 +76,24 @@ class RenderImage extends RenderBox {
|
|||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If non-null, apply this color filter to the image before painint.
|
|
||||||
ColorFilter get colorFilter => _colorFilter;
|
|
||||||
ColorFilter _colorFilter;
|
ColorFilter _colorFilter;
|
||||||
void set colorFilter (ColorFilter value) {
|
|
||||||
if (value == _colorFilter)
|
// Should we make the transfer mode configurable?
|
||||||
|
void _updateColorFilter() {
|
||||||
|
if (_color == null)
|
||||||
|
_colorFilter = null;
|
||||||
|
else
|
||||||
|
_colorFilter = new ColorFilter.mode(_color, TransferMode.srcIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If non-null, apply this color filter to the image before painting.
|
||||||
|
Color get color => _color;
|
||||||
|
Color _color;
|
||||||
|
void set color (Color value) {
|
||||||
|
if (value == _color)
|
||||||
return;
|
return;
|
||||||
_colorFilter = value;
|
_color = value;
|
||||||
|
_updateColorFilter();
|
||||||
markNeedsPaint();
|
markNeedsPaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1482,7 +1482,7 @@ class RawImage extends LeafRenderObjectWidget {
|
|||||||
this.image,
|
this.image,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.colorFilter,
|
this.color,
|
||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.repeat: ImageRepeat.noRepeat,
|
this.repeat: ImageRepeat.noRepeat,
|
||||||
@ -1504,8 +1504,8 @@ class RawImage extends LeafRenderObjectWidget {
|
|||||||
/// aspect ratio.
|
/// aspect ratio.
|
||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
/// If non-null, apply this color filter to the image before painint.
|
/// If non-null, apply this color filter to the image before painting.
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
|
|
||||||
/// How to inscribe the image into the place allocated during layout.
|
/// How to inscribe the image into the place allocated during layout.
|
||||||
final ImageFit fit;
|
final ImageFit fit;
|
||||||
@ -1533,7 +1533,7 @@ class RawImage extends LeafRenderObjectWidget {
|
|||||||
image: image,
|
image: image,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
colorFilter: colorFilter,
|
color: color,
|
||||||
fit: fit,
|
fit: fit,
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
repeat: repeat,
|
repeat: repeat,
|
||||||
@ -1543,7 +1543,7 @@ class RawImage extends LeafRenderObjectWidget {
|
|||||||
renderObject.image = image;
|
renderObject.image = image;
|
||||||
renderObject.width = width;
|
renderObject.width = width;
|
||||||
renderObject.height = height;
|
renderObject.height = height;
|
||||||
renderObject.colorFilter = colorFilter;
|
renderObject.color = color;
|
||||||
renderObject.alignment = alignment;
|
renderObject.alignment = alignment;
|
||||||
renderObject.fit = fit;
|
renderObject.fit = fit;
|
||||||
renderObject.repeat = repeat;
|
renderObject.repeat = repeat;
|
||||||
@ -1566,7 +1566,7 @@ class RawImageResource extends StatefulComponent {
|
|||||||
this.image,
|
this.image,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.colorFilter,
|
this.color,
|
||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.repeat: ImageRepeat.noRepeat,
|
this.repeat: ImageRepeat.noRepeat,
|
||||||
@ -1590,8 +1590,8 @@ class RawImageResource extends StatefulComponent {
|
|||||||
/// aspect ratio.
|
/// aspect ratio.
|
||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
/// If non-null, apply this color filter to the image before painint.
|
/// If non-null, apply this color filter to the image before painting.
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
|
|
||||||
/// How to inscribe the image into the place allocated during layout.
|
/// How to inscribe the image into the place allocated during layout.
|
||||||
final ImageFit fit;
|
final ImageFit fit;
|
||||||
@ -1649,7 +1649,7 @@ class _ImageListenerState extends State<RawImageResource> {
|
|||||||
image: _resolvedImage,
|
image: _resolvedImage,
|
||||||
width: config.width,
|
width: config.width,
|
||||||
height: config.height,
|
height: config.height,
|
||||||
colorFilter: config.colorFilter,
|
color: config.color,
|
||||||
fit: config.fit,
|
fit: config.fit,
|
||||||
alignment: config.alignment,
|
alignment: config.alignment,
|
||||||
repeat: config.repeat,
|
repeat: config.repeat,
|
||||||
@ -1665,7 +1665,7 @@ class NetworkImage extends StatelessComponent {
|
|||||||
this.src,
|
this.src,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.colorFilter,
|
this.color,
|
||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.repeat: ImageRepeat.noRepeat,
|
this.repeat: ImageRepeat.noRepeat,
|
||||||
@ -1687,8 +1687,8 @@ class NetworkImage extends StatelessComponent {
|
|||||||
/// aspect ratio.
|
/// aspect ratio.
|
||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
/// If non-null, apply this color filter to the image before painint.
|
/// If non-null, apply this color filter to the image before painting.
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
|
|
||||||
/// How to inscribe the image into the place allocated during layout.
|
/// How to inscribe the image into the place allocated during layout.
|
||||||
final ImageFit fit;
|
final ImageFit fit;
|
||||||
@ -1717,7 +1717,7 @@ class NetworkImage extends StatelessComponent {
|
|||||||
image: imageCache.load(src),
|
image: imageCache.load(src),
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
colorFilter: colorFilter,
|
color: color,
|
||||||
fit: fit,
|
fit: fit,
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
repeat: repeat,
|
repeat: repeat,
|
||||||
@ -1763,7 +1763,7 @@ class AsyncImage extends StatelessComponent {
|
|||||||
this.provider,
|
this.provider,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.colorFilter,
|
this.color,
|
||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.repeat: ImageRepeat.noRepeat,
|
this.repeat: ImageRepeat.noRepeat,
|
||||||
@ -1785,8 +1785,8 @@ class AsyncImage extends StatelessComponent {
|
|||||||
/// aspect ratio.
|
/// aspect ratio.
|
||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
/// If non-null, apply this color filter to the image before painint.
|
/// If non-null, apply this color filter to the image before painting.
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
|
|
||||||
/// How to inscribe the image into the place allocated during layout.
|
/// How to inscribe the image into the place allocated during layout.
|
||||||
final ImageFit fit;
|
final ImageFit fit;
|
||||||
@ -1815,7 +1815,7 @@ class AsyncImage extends StatelessComponent {
|
|||||||
image: imageCache.loadProvider(provider),
|
image: imageCache.loadProvider(provider),
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
colorFilter: colorFilter,
|
color: color,
|
||||||
fit: fit,
|
fit: fit,
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
repeat: repeat,
|
repeat: repeat,
|
||||||
@ -1837,7 +1837,7 @@ class AssetImage extends StatelessComponent {
|
|||||||
this.bundle,
|
this.bundle,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.colorFilter,
|
this.color,
|
||||||
this.fit,
|
this.fit,
|
||||||
this.alignment,
|
this.alignment,
|
||||||
this.repeat: ImageRepeat.noRepeat,
|
this.repeat: ImageRepeat.noRepeat,
|
||||||
@ -1865,8 +1865,8 @@ class AssetImage extends StatelessComponent {
|
|||||||
/// aspect ratio.
|
/// aspect ratio.
|
||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
/// If non-null, apply this color filter to the image before painint.
|
/// If non-null, apply this color filter to the image before painting.
|
||||||
final ColorFilter colorFilter;
|
final Color color;
|
||||||
|
|
||||||
/// How to inscribe the image into the place allocated during layout.
|
/// How to inscribe the image into the place allocated during layout.
|
||||||
final ImageFit fit;
|
final ImageFit fit;
|
||||||
@ -1895,7 +1895,7 @@ class AssetImage extends StatelessComponent {
|
|||||||
image: (bundle ?? DefaultAssetBundle.of(context)).loadImage(name),
|
image: (bundle ?? DefaultAssetBundle.of(context)).loadImage(name),
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
colorFilter: colorFilter,
|
color: color,
|
||||||
fit: fit,
|
fit: fit,
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
repeat: repeat,
|
repeat: repeat,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user