Unverified Commit 4bf03c6c authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

implicit-casts:false in flutter_test (#44996)

parent adc73510
include: ../analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter:
rules:
avoid_as: false # Disabled so we can gradually migrate to no implicit dynamic.
......@@ -135,7 +135,7 @@ class LocalComparisonOutput {
if (result.diffs != null) {
additionalFeedback = '\nFailure feedback can be found at '
'${path.join(basedir.path, 'failures')}';
final Map<String, Image> diffs = result.diffs;
final Map<String, Image> diffs = result.diffs.cast<String, Image>();
diffs.forEach((String name, Image image) {
final File output = getFailureFile(
key.isEmpty ? name : name + '_' + key,
......
......@@ -196,7 +196,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
Future<Evaluation> evaluate(WidgetTester tester) async {
final SemanticsNode root = tester.binding.pipelineOwner.semanticsOwner.rootSemanticsNode;
final RenderView renderView = tester.binding.renderView;
final OffsetLayer layer = renderView.debugLayer;
final OffsetLayer layer = renderView.debugLayer as OffsetLayer;
ui.Image image;
final ByteData byteData = await tester.binding.runAsync<ByteData>(() async {
// Needs to be the same pixel ratio otherwise our dimensions won't match the
......@@ -231,7 +231,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
Rect paintBounds;
if (elements.length == 1) {
final Element element = elements.single;
final RenderBox renderObject = element.renderObject;
final RenderBox renderObject = element.renderObject as RenderBox;
element.renderObject.paintBounds;
paintBounds = Rect.fromPoints(
renderObject.localToGlobal(element.renderObject.paintBounds.topLeft - const Offset(4.0, 4.0)),
......@@ -406,15 +406,15 @@ class _ContrastReport {
if (r <= 0.03928)
r /= 12.92;
else
r = math.pow((r + 0.055)/ 1.055, 2.4);
r = math.pow((r + 0.055)/ 1.055, 2.4).toDouble();
if (g <= 0.03928)
g /= 12.92;
else
g = math.pow((g + 0.055)/ 1.055, 2.4);
g = math.pow((g + 0.055)/ 1.055, 2.4).toDouble();
if (b <= 0.03928)
b /= 12.92;
else
b = math.pow((b + 0.055)/ 1.055, 2.4);
b = math.pow((b + 0.055)/ 1.055, 2.4).toDouble();
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
}
......
......@@ -1335,7 +1335,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}
@override
_LiveTestRenderView get renderView => super.renderView;
_LiveTestRenderView get renderView => super.renderView as _LiveTestRenderView;
void _handleViewNeedsPaint() {
_viewNeedsPaint = true;
......@@ -1577,7 +1577,7 @@ class _LiveTestRenderView extends RenderView {
}) : super(configuration: configuration, window: window);
@override
TestViewConfiguration get configuration => super.configuration;
TestViewConfiguration get configuration => super.configuration as TestViewConfiguration;
@override
set configuration(covariant TestViewConfiguration value) { super.configuration = value; }
......
......@@ -62,7 +62,7 @@ abstract class WidgetController {
/// * Use [widgetList] if you expect to match several widgets and want all of them.
T widget<T extends Widget>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().single.widget;
return finder.evaluate().single.widget as T;
}
/// The first matching widget according to a depth-first pre-order
......@@ -73,7 +73,7 @@ abstract class WidgetController {
/// * Use [widget] if you only expect to match one widget.
T firstWidget<T extends Widget>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().first.widget;
return finder.evaluate().first.widget as T;
}
/// The matching widgets in the widget tree.
......@@ -83,7 +83,7 @@ abstract class WidgetController {
Iterable<T> widgetList<T extends Widget>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().map<T>((Element element) {
final T result = element.widget;
final T result = element.widget as T;
return result;
});
}
......@@ -107,7 +107,7 @@ abstract class WidgetController {
/// * Use [elementList] if you expect to match several elements and want all of them.
T element<T extends Element>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().single;
return finder.evaluate().single as T;
}
/// The first matching element according to a depth-first pre-order
......@@ -118,7 +118,7 @@ abstract class WidgetController {
/// * Use [element] if you only expect to match one element.
T firstElement<T extends Element>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().first;
return finder.evaluate().first as T;
}
/// The matching elements in the widget tree.
......@@ -127,7 +127,7 @@ abstract class WidgetController {
/// * Use [firstElement] if you expect to match several but only want the first.
Iterable<T> elementList<T extends Element>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate();
return finder.evaluate().cast<T>();
}
/// All states currently in the widget tree (lazy pre-order traversal).
......@@ -179,7 +179,7 @@ abstract class WidgetController {
T _stateOf<T extends State>(Element element, Finder finder) {
TestAsyncUtils.guardSync();
if (element is StatefulElement)
return element.state;
return element.state as T;
throw StateError('Widget of type ${element.widget.runtimeType}, with ${finder.description}, is not a StatefulWidget.');
}
......@@ -204,7 +204,7 @@ abstract class WidgetController {
/// * Use [renderObjectList] if you expect to match several render objects and want all of them.
T renderObject<T extends RenderObject>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().single.renderObject;
return finder.evaluate().single.renderObject as T;
}
/// The render object of the first matching widget according to a
......@@ -215,7 +215,7 @@ abstract class WidgetController {
/// * Use [renderObject] if you only expect to match one render object.
T firstRenderObject<T extends RenderObject>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().first.renderObject;
return finder.evaluate().first.renderObject as T;
}
/// The render objects of the matching widgets in the widget tree.
......@@ -225,7 +225,7 @@ abstract class WidgetController {
Iterable<T> renderObjectList<T extends RenderObject>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().map<T>((Element element) {
final T result = element.renderObject;
final T result = element.renderObject as T;
return result;
});
}
......@@ -644,7 +644,7 @@ abstract class WidgetController {
Offset _getElementPoint(Finder finder, Offset sizeToPoint(Size size)) {
TestAsyncUtils.guardSync();
final Element element = finder.evaluate().single;
final RenderBox box = element.renderObject;
final RenderBox box = element.renderObject as RenderBox;
assert(box != null);
return box.localToGlobal(sizeToPoint(box.size));
}
......@@ -654,7 +654,7 @@ abstract class WidgetController {
Size getSize(Finder finder) {
TestAsyncUtils.guardSync();
final Element element = finder.evaluate().single;
final RenderBox box = element.renderObject;
final RenderBox box = element.renderObject as RenderBox;
assert(box != null);
return box.size;
}
......
......@@ -501,7 +501,7 @@ class _HitTestableFinder extends ChainedFinder {
@override
Iterable<Element> filter(Iterable<Element> parentCandidates) sync* {
for (final Element candidate in parentCandidates) {
final RenderBox box = candidate.renderObject;
final RenderBox box = candidate.renderObject as RenderBox;
assert(box != null);
final Offset absoluteOffset = box.localToGlobal(alignment.alongSize(box.size));
final HitTestResult hitResult = HitTestResult();
......@@ -544,14 +544,13 @@ class _TextFinder extends MatchFinder {
@override
bool matches(Element candidate) {
if (candidate.widget is Text) {
final Text textWidget = candidate.widget;
if (textWidget.data != null)
return textWidget.data == text;
return textWidget.textSpan.toPlainText() == text;
} else if (candidate.widget is EditableText) {
final EditableText editable = candidate.widget;
return editable.controller.text == text;
final Widget widget = candidate.widget;
if (widget is Text) {
if (widget.data != null)
return widget.data == text;
return widget.textSpan.toPlainText() == text;
} else if (widget is EditableText) {
return widget.controller.text == text;
}
return false;
}
......
......@@ -662,7 +662,7 @@ class _FindsWidgetMatcher extends Matcher {
Map<dynamic, dynamic> matchState,
bool verbose,
) {
final Finder finder = matchState[Finder];
final Finder finder = matchState[Finder] as Finder;
final int count = finder.evaluate().length;
if (count == 0) {
assert(min != null && min > 0);
......@@ -790,7 +790,7 @@ class _EqualsIgnoringHashCodes extends Matcher {
@override
bool matches(dynamic object, Map<dynamic, dynamic> matchState) {
final String description = _normalize(object);
final String description = _normalize(object as String);
if (_value != description) {
matchState[_mismatchedValueKey] = description;
return false;
......@@ -811,7 +811,7 @@ class _EqualsIgnoringHashCodes extends Matcher {
bool verbose,
) {
if (matchState.containsKey(_mismatchedValueKey)) {
final String actualValue = matchState[_mismatchedValueKey];
final String actualValue = matchState[_mismatchedValueKey] as String;
// Leading whitespace is added so that lines in the multi-line
// description returned by addDescriptionOf are all indented equally
// which makes the output easier to read for this case.
......@@ -860,7 +860,7 @@ class _HasGoodToStringDeep extends Matcher {
@override
bool matches(dynamic object, Map<dynamic, dynamic> matchState) {
final List<String> issues = <String>[];
String description = object.toStringDeep();
String description = object.toStringDeep() as String;
if (description.endsWith('\n')) {
// Trim off trailing \n as the remaining calculations assume
// the description does not end with a trailing \n.
......@@ -898,7 +898,7 @@ class _HasGoodToStringDeep extends Matcher {
const String prefixOtherLines = 'PREFIX_OTHER_LINES_';
final List<String> prefixIssues = <String>[];
String descriptionWithPrefixes =
object.toStringDeep(prefixLineOne: prefixLineOne, prefixOtherLines: prefixOtherLines);
object.toStringDeep(prefixLineOne: prefixLineOne, prefixOtherLines: prefixOtherLines) as String;
if (descriptionWithPrefixes.endsWith('\n')) {
// Trim off trailing \n as the remaining calculations assume
// the description does not end with a trailing \n.
......@@ -944,8 +944,7 @@ class _HasGoodToStringDeep extends Matcher {
bool verbose,
) {
if (matchState.containsKey(_toStringDeepErrorDescriptionKey)) {
return mismatchDescription.add(
matchState[_toStringDeepErrorDescriptionKey]);
return mismatchDescription.add(matchState[_toStringDeepErrorDescriptionKey] as String);
}
return mismatchDescription;
}
......@@ -1030,7 +1029,9 @@ double _rectDistance(Rect a, Rect b) {
}
double _sizeDistance(Size a, Size b) {
final Offset delta = b - a;
// TODO(a14n): remove ignore when lint is updated, https://github.com/dart-lang/linter/issues/1843
// ignore: unnecessary_parenthesis
final Offset delta = (b - a) as Offset;
return delta.distance;
}
......@@ -1063,7 +1064,7 @@ Matcher within<T>({
@required T from,
DistanceFunction<T> distanceFunction,
}) {
distanceFunction ??= _kStandardDistanceFunctions[T];
distanceFunction ??= _kStandardDistanceFunctions[T] as DistanceFunction<T>;
if (distanceFunction == null) {
throw ArgumentError(
......@@ -1089,7 +1090,7 @@ class _IsWithinDistance<T> extends Matcher {
return false;
if (object == value)
return true;
final T test = object;
final T test = object as T;
final num distance = distanceFunction(test, value);
if (distance < 0) {
throw ArgumentError(
......@@ -1130,7 +1131,7 @@ class _MoreOrLessEquals extends Matcher {
return false;
if (object == value)
return true;
final double test = object;
final double test = object as double;
return (test - value).abs() <= epsilon;
}
......@@ -1280,7 +1281,7 @@ abstract class _FailWithDescriptionMatcher extends Matcher {
Map<dynamic, dynamic> matchState,
bool verbose,
) {
return mismatchDescription.add(matchState['failure']);
return mismatchDescription.add(matchState['failure'] as String);
}
}
......@@ -1325,10 +1326,10 @@ abstract class _MatchRenderObject<M extends RenderObject, T extends RenderObject
final RenderObject renderObject = nodes.single.renderObject;
if (renderObject.runtimeType == T)
return renderObjectMatchesT(matchState, renderObject);
return renderObjectMatchesT(matchState, renderObject as T);
if (renderObject.runtimeType == M)
return renderObjectMatchesM(matchState, renderObject);
return renderObjectMatchesM(matchState, renderObject as M);
return failWithDescription(matchState, 'had a root render object of type: ${renderObject.runtimeType}');
}
......@@ -1363,7 +1364,7 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderPhysicalShape renderObject) {
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
final ShapeBorderClipper shapeClipper = renderObject.clipper;
final ShapeBorderClipper shapeClipper = renderObject.clipper as ShapeBorderClipper;
if (borderRadius != null && !assertRoundedRectangle(shapeClipper, borderRadius, matchState))
return false;
......@@ -1393,7 +1394,7 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re
bool assertRoundedRectangle(ShapeBorderClipper shapeClipper, BorderRadius borderRadius, Map<dynamic, dynamic> matchState) {
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder)
return failWithDescription(matchState, 'had shape border: ${shapeClipper.shape}');
final RoundedRectangleBorder border = shapeClipper.shape;
final RoundedRectangleBorder border = shapeClipper.shape as RoundedRectangleBorder;
if (border.borderRadius != borderRadius)
return failWithDescription(matchState, 'had borderRadius: ${border.borderRadius}');
return true;
......@@ -1431,7 +1432,7 @@ class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, Re
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderPhysicalShape renderObject) {
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
final ShapeBorderClipper shapeClipper = renderObject.clipper;
final ShapeBorderClipper shapeClipper = renderObject.clipper as ShapeBorderClipper;
if (shapeClipper.shape != shape)
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
......@@ -1470,10 +1471,10 @@ class _ClipsWithBoundingRect extends _MatchRenderObject<RenderClipPath, RenderCl
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderClipPath renderObject) {
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
final ShapeBorderClipper shapeClipper = renderObject.clipper;
final ShapeBorderClipper shapeClipper = renderObject.clipper as ShapeBorderClipper;
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder)
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
final RoundedRectangleBorder border = shapeClipper.shape;
final RoundedRectangleBorder border = shapeClipper.shape as RoundedRectangleBorder;
if (border.borderRadius != BorderRadius.zero)
return failWithDescription(matchState, 'borderRadius was: ${border.borderRadius}');
return true;
......@@ -1505,10 +1506,10 @@ class _ClipsWithBoundingRRect extends _MatchRenderObject<RenderClipPath, RenderC
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderClipPath renderObject) {
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
final ShapeBorderClipper shapeClipper = renderObject.clipper;
final ShapeBorderClipper shapeClipper = renderObject.clipper as ShapeBorderClipper;
if (shapeClipper.shape.runtimeType != RoundedRectangleBorder)
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
final RoundedRectangleBorder border = shapeClipper.shape;
final RoundedRectangleBorder border = shapeClipper.shape as RoundedRectangleBorder;
if (border.borderRadius != borderRadius)
return failWithDescription(matchState, 'had borderRadius: ${border.borderRadius}');
return true;
......@@ -1528,7 +1529,7 @@ class _ClipsWithShapeBorder extends _MatchRenderObject<RenderClipPath, RenderCli
bool renderObjectMatchesM(Map<dynamic, dynamic> matchState, RenderClipPath renderObject) {
if (renderObject.clipper.runtimeType != ShapeBorderClipper)
return failWithDescription(matchState, 'clipper was: ${renderObject.clipper}');
final ShapeBorderClipper shapeClipper = renderObject.clipper;
final ShapeBorderClipper shapeClipper = renderObject.clipper as ShapeBorderClipper;
if (shapeClipper.shape != shape)
return failWithDescription(matchState, 'shape was: ${shapeClipper.shape}');
return true;
......@@ -1609,7 +1610,7 @@ class _CoversSameAreaAs extends Matcher {
Map<dynamic, dynamic> matchState,
bool verbose,
) {
return mismatchDescription.add(matchState['failure']);
return mismatchDescription.add(matchState['failure'] as String);
}
@override
......@@ -1638,11 +1639,11 @@ class _ColorMatcher extends Matcher {
Future<ui.Image> _captureImage(Element element) {
RenderObject renderObject = element.renderObject;
while (!renderObject.isRepaintBoundary) {
renderObject = renderObject.parent;
renderObject = renderObject.parent as RenderObject;
assert(renderObject != null);
}
assert(!renderObject.debugNeedsPaint);
final OffsetLayer layer = renderObject.debugLayer;
final OffsetLayer layer = renderObject.debugLayer as OffsetLayer;
return layer.toImage(renderObject.paintBounds);
}
......@@ -1673,7 +1674,7 @@ class _MatchesReferenceImage extends AsyncMatcher {
} else if (item is ui.Image) {
imageFuture = Future<ui.Image>.value(item);
} else {
final Finder finder = item;
final Finder finder = item as Finder;
final Iterable<Element> elements = finder.evaluate();
if (elements.isEmpty) {
return 'could not be rendered because no widget was found';
......@@ -1683,7 +1684,7 @@ class _MatchesReferenceImage extends AsyncMatcher {
imageFuture = _captureImage(elements.single);
}
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
return binding.runAsync<String>(() async {
final ui.Image image = await imageFuture;
final ByteData bytes = await image.toByteData();
......@@ -1727,7 +1728,7 @@ class _MatchesGoldenFile extends AsyncMatcher {
} else if (item is ui.Image) {
imageFuture = Future<ui.Image>.value(item);
} else {
final Finder finder = item;
final Finder finder = item as Finder;
final Iterable<Element> elements = finder.evaluate();
if (elements.isEmpty) {
return 'could not be rendered because no widget was found';
......@@ -1739,7 +1740,7 @@ class _MatchesGoldenFile extends AsyncMatcher {
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
return binding.runAsync<String>(() async {
final ui.Image image = await imageFuture;
final ByteData bytes = await image.toByteData(format: ui.ImageByteFormat.png);
......@@ -1845,7 +1846,7 @@ class _MatchesSemanticsData extends Matcher {
description.add(' with custom hints: $hintOverrides');
if (children != null) {
description.add(' with children:\n');
for (_MatchesSemanticsData child in children)
for (_MatchesSemanticsData child in children.cast<_MatchesSemanticsData>())
child.describe(description);
}
return description;
......@@ -1858,7 +1859,7 @@ class _MatchesSemanticsData extends Matcher {
if (node == null)
return failWithDescription(matchState, 'No SemanticsData provided. '
'Maybe you forgot to enable semantics?');
final SemanticsData data = node is SemanticsNode ? node.getSemanticsData() : node;
final SemanticsData data = node is SemanticsNode ? node.getSemanticsData() : (node as SemanticsData);
if (label != null && label != data.label)
return failWithDescription(matchState, 'label was: ${data.label}');
if (hint != null && hint != data.hint)
......@@ -1956,7 +1957,7 @@ class _MatchesSemanticsData extends Matcher {
Map<dynamic, dynamic> matchState,
bool verbose,
) {
return mismatchDescription.add(matchState['failure']);
return mismatchDescription.add(matchState['failure'] as String);
}
}
......
......@@ -23,7 +23,7 @@ import 'package:test_api/test_api.dart';
Declarer _localDeclarer;
Declarer get _declarer {
final Declarer declarer = Zone.current[#test.declarer];
final Declarer declarer = Zone.current[#test.declarer] as Declarer;
if (declarer != null) {
return declarer;
}
......@@ -58,9 +58,9 @@ Future<void> _runGroup(Suite suiteConfig, Group group, List<Group> parents, _Rep
if (entry is Group) {
await _runGroup(suiteConfig, entry, parents, reporter);
} else if (entry.metadata.skip) {
await _runSkippedTest(suiteConfig, entry, parents, reporter);
await _runSkippedTest(suiteConfig, entry as Test, parents, reporter);
} else {
final Test test = entry;
final Test test = entry as Test;
await _runLiveTest(suiteConfig, test.load(suiteConfig, groups: parents), reporter);
}
}
......@@ -154,7 +154,7 @@ Future<void> _runSkippedTest(Suite suiteConfig, Test test, List<Group> parents,
@isTest
void test(
Object description,
Function body, {
dynamic Function() body, {
String testOn,
Timeout timeout,
dynamic skip,
......@@ -163,7 +163,8 @@ void test(
int retry,
}) {
_declarer.test(
description.toString(), body,
description.toString(),
body,
testOn: testOn,
timeout: timeout,
skip: skip,
......@@ -221,7 +222,7 @@ void test(
/// If multiple platforms match, the annotations apply in order as through
/// they were in nested groups.
@isTestGroup
void group(Object description, Function body, { dynamic skip }) {
void group(Object description, void Function() body, { dynamic skip }) {
_declarer.group(description.toString(), body, skip: skip);
}
......@@ -236,7 +237,7 @@ void group(Object description, Function body, { dynamic skip }) {
///
/// Each callback at the top level or in a given group will be run in the order
/// they were declared.
void setUp(Function body) {
void setUp(dynamic Function() body) {
_declarer.setUp(body);
}
......@@ -253,7 +254,7 @@ void setUp(Function body) {
/// reverse of the order they were declared.
///
/// See also [addTearDown], which adds tear-downs to a running test.
void tearDown(Function body) {
void tearDown(dynamic Function() body) {
_declarer.tearDown(body);
}
......@@ -270,7 +271,7 @@ void tearDown(Function body) {
/// dependencies between tests that should be isolated. In general, you should
/// prefer [setUp], and only use [setUpAll] if the callback is prohibitively
/// slow.
void setUpAll(Function body) {
void setUpAll(dynamic Function() body) {
_declarer.setUpAll(body);
}
......@@ -285,7 +286,7 @@ void setUpAll(Function body) {
/// dependencies between tests that should be isolated. In general, you should
/// prefer [tearDown], and only use [tearDownAll] if the callback is
/// prohibitively slow.
void tearDownAll(Function body) {
void tearDownAll(dynamic Function() body) {
_declarer.tearDownAll(body);
}
......
......@@ -87,8 +87,8 @@ class TestTextInput {
log.add(methodCall);
switch (methodCall.method) {
case 'TextInput.setClient':
_client = methodCall.arguments[0];
setClientArgs = methodCall.arguments[1];
_client = methodCall.arguments[0] as int;
setClientArgs = methodCall.arguments[1] as Map<String, dynamic>;
break;
case 'TextInput.clearClient':
_client = 0;
......@@ -97,7 +97,7 @@ class TestTextInput {
onCleared();
break;
case 'TextInput.setEditingState':
editingState = methodCall.arguments;
editingState = methodCall.arguments as Map<String, dynamic>;
break;
case 'TextInput.show':
_isVisible = true;
......
......@@ -107,7 +107,7 @@ void testWidgets(
Duration initialTimeout,
bool semanticsEnabled = true,
}) {
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
final WidgetTester tester = WidgetTester._(binding);
test(
description,
......@@ -198,7 +198,7 @@ Future<void> benchmarkWidgets(
print('└─────────────────────────────────────────────────╌┄┈ 🐢');
return true;
}());
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
assert(binding is! AutomatedTestWidgetsFlutterBinding);
final WidgetTester tester = WidgetTester._(binding);
SemanticsHandle semanticsHandle;
......@@ -284,7 +284,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// The binding instance used by the testing framework.
@override
TestWidgetsFlutterBinding get binding => super.binding;
TestWidgetsFlutterBinding get binding => super.binding as TestWidgetsFlutterBinding;
/// Renders the UI from the given [widget].
///
......@@ -485,9 +485,10 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
@override
void dispatchEvent(PointerEvent event, HitTestResult result) {
if (event is PointerDownEvent) {
final RenderObject innerTarget = result.path.firstWhere(
(HitTestEntry candidate) => candidate.target is RenderObject,
).target;
final RenderObject innerTarget = result.path
.map((HitTestEntry candidate) => candidate.target)
.whereType<RenderObject>()
.first;
final Element innerTargetElement = collectAllElementsFrom(
binding.renderViewElement,
skipOffstage: true,
......@@ -515,8 +516,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
break;
totalNumber += 1; // optimistically assume we'll be able to describe it
if (element.widget is Tooltip) {
final Tooltip widget = element.widget;
final Widget widget = element.widget;
if (widget is Tooltip) {
final Iterable<Element> matches = find.byTooltip(widget.message).evaluate();
if (matches.length == 1) {
debugPrint(' find.byTooltip(\'${widget.message}\')');
......@@ -524,9 +525,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
}
}
if (element.widget is Text) {
if (widget is Text) {
assert(descendantText == null);
final Text widget = element.widget;
final Iterable<Element> matches = find.text(widget.data).evaluate();
descendantText = widget.data;
if (matches.length == 1) {
......@@ -535,13 +535,13 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
}
}
if (element.widget.key is ValueKey<dynamic>) {
final ValueKey<dynamic> key = element.widget.key;
final Key key = widget.key;
if (key is ValueKey<dynamic>) {
String keyLabel;
if (key is ValueKey<int> ||
key is ValueKey<double> ||
key is ValueKey<bool>) {
keyLabel = 'const ${element.widget.key.runtimeType}(${key.value})';
keyLabel = 'const ${key.runtimeType}(${key.value})';
} else if (key is ValueKey<String>) {
keyLabel = 'const Key(\'${key.value}\')';
}
......@@ -554,20 +554,20 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
}
}
if (!_isPrivate(element.widget.runtimeType)) {
if (!_isPrivate(widget.runtimeType)) {
if (numberOfTypes < 5) {
final Iterable<Element> matches = find.byType(element.widget.runtimeType).evaluate();
final Iterable<Element> matches = find.byType(widget.runtimeType).evaluate();
if (matches.length == 1) {
debugPrint(' find.byType(${element.widget.runtimeType})');
debugPrint(' find.byType(${widget.runtimeType})');
numberOfTypes += 1;
continue;
}
}
if (descendantText != null && numberOfWithTexts < 5) {
final Iterable<Element> matches = find.widgetWithText(element.widget.runtimeType, descendantText).evaluate();
final Iterable<Element> matches = find.widgetWithText(widget.runtimeType, descendantText).evaluate();
if (matches.length == 1) {
debugPrint(' find.widgetWithText(${element.widget.runtimeType}, \'$descendantText\')');
debugPrint(' find.widgetWithText(${widget.runtimeType}, \'$descendantText\')');
numberOfWithTexts += 1;
continue;
}
......@@ -842,7 +842,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
RenderObject renderObject = element.findRenderObject();
SemanticsNode result = renderObject.debugSemantics;
while (renderObject != null && result == null) {
renderObject = renderObject?.parent;
renderObject = renderObject?.parent as RenderObject;
result = renderObject?.debugSemantics;
}
if (result == null)
......
......@@ -128,7 +128,7 @@ void main() {
final Text text = find.descendant(
of: find.byKey(key1),
matching: find.byType(Text),
).last.evaluate().single.widget;
).last.evaluate().single.widget as Text;
expect(text.data, '1');
});
......
......@@ -77,7 +77,7 @@ void main() {
test('is initialized by test framework', () {
expect(goldenFileComparator, isNotNull);
expect(goldenFileComparator, isInstanceOf<LocalFileComparator>());
final LocalFileComparator comparator = goldenFileComparator;
final LocalFileComparator comparator = goldenFileComparator as LocalFileComparator;
expect(comparator.basedir.path, contains('flutter_test'));
});
});
......
......@@ -159,7 +159,7 @@ void main() {
real_test.expect(information[3], isInstanceOf<DiagnosticsProperty<void>>());
real_test.expect(information[4], isInstanceOf<DiagnosticsProperty<void>>());
real_test.expect(information[5], isInstanceOf<DiagnosticsStackTrace>());
final DiagnosticsStackTrace stackTraceProperty = information[5];
final DiagnosticsStackTrace stackTraceProperty = information[5] as DiagnosticsStackTrace;
real_test.expect(stackTraceProperty.name, '\nWhen the first method was called, this was the stack');
real_test.expect(stackTraceProperty.value, isInstanceOf<StackTrace>());
}
......
......@@ -11,7 +11,7 @@ void testConfig(
String expectedStringValue, {
Map<Type, dynamic> otherExpectedValues = const <Type, dynamic>{int: isNull},
}) {
final String actualStringValue = Zone.current[String];
final String actualStringValue = Zone.current[String] as String;
final Map<Type, dynamic> otherActualValues = otherExpectedValues.map<Type, dynamic>(
(Type key, dynamic value) {
return MapEntry<Type, dynamic>(key, Zone.current[key]);
......
......@@ -193,7 +193,7 @@ void main() {
TestFailure failure;
try {
expect(find.text('foo', skipOffstage: false), findsOneWidget);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......@@ -216,7 +216,7 @@ void main() {
TestFailure failure;
try {
expect(find.text('foo', skipOffstage: false), findsNothing);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......@@ -234,7 +234,7 @@ void main() {
TestFailure failure;
try {
expect(find.text('foo'), findsNothing);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......@@ -289,7 +289,7 @@ void main() {
TestFailure failure;
try {
expect(find.byElementPredicate((_) => false, description: customDescription), findsOneWidget);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......@@ -306,7 +306,7 @@ void main() {
TestFailure failure;
try {
expect(find.byWidgetPredicate((_) => false, description: customDescription), findsOneWidget);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......@@ -360,7 +360,7 @@ void main() {
of: find.widgetWithText(Column, 'foo'),
matching: find.text('bar'),
), findsOneWidget);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......@@ -422,7 +422,7 @@ void main() {
of: find.text('bar'),
matching: find.widgetWithText(Column, 'foo'),
), findsOneWidget);
} catch (e) {
} on TestFailure catch (e) {
failure = e;
}
......
......@@ -224,7 +224,7 @@ void verifyThatTestWindowCanFakeProperty<WindowPropertyType>({
TestWidgetsFlutterBinding retrieveTestBinding(WidgetTester tester) {
final WidgetsBinding binding = tester.binding;
assert(binding is TestWidgetsFlutterBinding);
final TestWidgetsFlutterBinding testBinding = binding;
final TestWidgetsFlutterBinding testBinding = binding as TestWidgetsFlutterBinding;
return testBinding;
}
......
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