Commit 00a00def authored by Adam Barth's avatar Adam Barth

Add a test for icon opacity crash

Fixes #2361
parent 8af3dde3
......@@ -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(
......
// 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)));
});
});
}
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment