diff --git a/packages/flutter/lib/src/material/icon.dart b/packages/flutter/lib/src/material/icon.dart index 95c2b0d0cf4..6290b46e62f 100644 --- a/packages/flutter/lib/src/material/icon.dart +++ b/packages/flutter/lib/src/material/icon.dart @@ -63,7 +63,7 @@ class Icon extends StatelessComponent { final double iconOpacity = IconTheme.of(context)?.clampedOpacity ?? 1.0; Color iconColor = color ?? _getDefaultColor(context); if (iconOpacity != 1.0) - iconColor = iconColor.withAlpha((255.0 * iconColor.opacity * iconOpacity).round()); + iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity); return new ExcludeSemantics( child: new SizedBox( diff --git a/packages/flutter/test/widget/icon_test.dart b/packages/flutter/test/widget/icon_test.dart new file mode 100644 index 00000000000..89064561365 --- /dev/null +++ b/packages/flutter/test/widget/icon_test.dart @@ -0,0 +1,25 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter/material.dart'; +import 'package:test/test.dart'; + +void main() { + test('Can set opacity for an Icon', () { + testWidgets((WidgetTester tester) { + tester.pumpWidget( + new IconTheme( + data: new IconThemeData( + color: Colors.green[500], + opacity: 0.5 + ), + child: new Icon(icon: Icons.add) + ) + ); + Text text = tester.findWidgetOfType(Text); + expect(text.style.color, equals(Colors.green[500].withOpacity(0.5))); + }); + }); +} diff --git a/packages/flutter_test/lib/src/instrumentation.dart b/packages/flutter_test/lib/src/instrumentation.dart index effb36f3284..abf05f374da 100644 --- a/packages/flutter_test/lib/src/instrumentation.dart +++ b/packages/flutter_test/lib/src/instrumentation.dart @@ -75,6 +75,15 @@ class Instrumentation { }); } + /// Returns the first [Widget] of the given [runtimeType], if any. Returns + /// null if there is no matching widget. + Widget findWidgetOfType(Type type) { + Element element = findElement((Element element) { + return element.widget.runtimeType == type; + }); + return element?.widget; + } + /// Returns the [State] object of the first element whose state has /// the given [runtimeType], if any. Returns null if there is no /// matching element.