From 56aa9208581dbf95b79b213c06b92152369f0ca0 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 8 Jul 2016 13:39:54 -0700 Subject: [PATCH] Improve how ImageIcon does opacity (#4847) Putting the opacity in the color is much faster than using an opacity widget because the opacity widget creates an offscreen buffer. Fixes #4651 --- .../flutter/lib/src/material/image_icon.dart | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/flutter/lib/src/material/image_icon.dart b/packages/flutter/lib/src/material/image_icon.dart index 50c2a3f9be..1afa30a431 100644 --- a/packages/flutter/lib/src/material/image_icon.dart +++ b/packages/flutter/lib/src/material/image_icon.dart @@ -61,9 +61,12 @@ class ImageIcon extends StatelessWidget { return new SizedBox(width: iconSize, height: iconSize); final double iconOpacity = iconTheme.opacity; - final Color iconColor = color ?? iconTheme.color; + Color iconColor = color ?? iconTheme.color; - Widget result = new Image( + if (iconOpacity != null && iconOpacity != 1.0) + iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity); + + return new Image( image: image, width: iconSize, height: iconSize, @@ -71,15 +74,6 @@ class ImageIcon extends StatelessWidget { fit: ImageFit.scaleDown, alignment: FractionalOffset.center ); - - if (iconOpacity != 1.0) { - result = new Opacity( - opacity: iconOpacity, - child: result - ); - } - - return result; } @override