Unverified Commit ef119187 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Convert some widgets tests to NNBD (#67782)

Migrating some more widget tests to NNBD.
parent 085f1daa
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -12,8 +10,8 @@ void main() { ...@@ -12,8 +10,8 @@ void main() {
testWidgets('FadeTransition', (WidgetTester tester) async { testWidgets('FadeTransition', (WidgetTester tester) async {
final DebugPrintCallback oldPrint = debugPrint; final DebugPrintCallback oldPrint = debugPrint;
final List<String> log = <String>[]; final List<String> log = <String>[];
debugPrint = (String message, { int wrapWidth }) { debugPrint = (String? message, { int? wrapWidth }) {
log.add(message); log.add(message!);
}; };
debugPrintBuildScope = true; debugPrintBuildScope = true;
final AnimationController controller = AnimationController( final AnimationController controller = AnimationController(
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -595,12 +593,11 @@ void main() { ...@@ -595,12 +593,11 @@ void main() {
List<Type> getLayers() { List<Type> getLayers() {
final List<Type> layers = <Type>[]; final List<Type> layers = <Type>[];
Layer layer = RendererBinding.instance.renderView.debugLayer; Layer? container = RendererBinding.instance!.renderView.debugLayer;
while (layer is ContainerLayer) { while (container is ContainerLayer) {
final ContainerLayer container = layer as ContainerLayer;
layers.add(container.runtimeType); layers.add(container.runtimeType);
expect(container.firstChild, same(container.lastChild)); expect(container.firstChild, same(container.lastChild));
layer = container.firstChild; container = container.firstChild;
} }
return layers; return layers;
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -63,18 +61,6 @@ void main() { ...@@ -63,18 +61,6 @@ void main() {
expect(box.size.width, 100.0); expect(box.size.width, 100.0);
}); });
testWidgets('Can pass null for flex', (WidgetTester tester) async {
await tester.pumpWidget(
Row(
textDirection: TextDirection.ltr,
children: const <Widget>[
Expanded(flex: null, child: Text('one', textDirection: TextDirection.ltr)),
Flexible(flex: null, child: Text('two', textDirection: TextDirection.ltr)),
],
),
);
});
testWidgets("Doesn't overflow because of floating point accumulated error", (WidgetTester tester) async { testWidgets("Doesn't overflow because of floating point accumulated error", (WidgetTester tester) async {
// both of these cases have failed in the past due to floating point issues // both of these cases have failed in the past due to floating point issues
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class TestFlowDelegate extends FlowDelegate { class TestFlowDelegate extends FlowDelegate {
TestFlowDelegate({this.startOffset}) : super(repaint: startOffset); TestFlowDelegate({required this.startOffset}) : super(repaint: startOffset);
final Animation<double> startOffset; final Animation<double> startOffset;
...@@ -23,7 +21,7 @@ class TestFlowDelegate extends FlowDelegate { ...@@ -23,7 +21,7 @@ class TestFlowDelegate extends FlowDelegate {
double dy = startOffset.value; double dy = startOffset.value;
for (int i = 0; i < context.childCount; ++i) { for (int i = 0; i < context.childCount; ++i) {
context.paintChild(i, transform: Matrix4.translationValues(0.0, dy, 0.0)); context.paintChild(i, transform: Matrix4.translationValues(0.0, dy, 0.0));
dy += 0.75 * context.getChildSize(i).height; dy += 0.75 * context.getChildSize(i)!.height;
} }
} }
...@@ -149,13 +147,13 @@ void main() { ...@@ -149,13 +147,13 @@ void main() {
], ],
), ),
); );
ContainerLayer layer = RendererBinding.instance.renderView.debugLayer; ContainerLayer? layer = RendererBinding.instance!.renderView.debugLayer;
while (layer != null && layer is! OpacityLayer) while (layer != null && layer is! OpacityLayer)
layer = layer.firstChild as ContainerLayer; layer = layer.firstChild as ContainerLayer?;
expect(layer, isA<OpacityLayer>()); expect(layer, isA<OpacityLayer>());
final OpacityLayer opacityLayer = layer as OpacityLayer; final OpacityLayer? opacityLayer = layer as OpacityLayer?;
expect(opacityLayer.alpha, equals(opacity * 255)); expect(opacityLayer!.alpha, equals(opacity * 255));
expect(layer.firstChild, isA<TransformLayer>()); expect(layer!.firstChild, isA<TransformLayer>());
}); });
testWidgets('Flow can set and update clipBehavior', (WidgetTester tester) async { testWidgets('Flow can set and update clipBehavior', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -18,7 +16,7 @@ void main() { ...@@ -18,7 +16,7 @@ void main() {
final GlobalKey widgetKey = GlobalKey(); final GlobalKey widgetKey = GlobalKey();
Future<BuildContext> setupWidget(WidgetTester tester) async { Future<BuildContext> setupWidget(WidgetTester tester) async {
await tester.pumpWidget(Container(key: widgetKey)); await tester.pumpWidget(Container(key: widgetKey));
return widgetKey.currentContext; return widgetKey.currentContext!;
} }
group(FocusNode, () { group(FocusNode, () {
...@@ -931,7 +929,7 @@ void main() { ...@@ -931,7 +929,7 @@ void main() {
}, variant: TargetPlatformVariant.all()); }, variant: TargetPlatformVariant.all());
testWidgets('Mouse events change initial focus highlight mode on mobile.', (WidgetTester tester) async { testWidgets('Mouse events change initial focus highlight mode on mobile.', (WidgetTester tester) async {
expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch)); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch));
RendererBinding.instance.initMouseTracker(); // Clear out the mouse state. RendererBinding.instance!.initMouseTracker(); // Clear out the mouse state.
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 0); final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 0);
addTearDown(gesture.removePointer); addTearDown(gesture.removePointer);
await gesture.moveTo(Offset.zero); await gesture.moveTo(Offset.zero);
...@@ -939,7 +937,7 @@ void main() { ...@@ -939,7 +937,7 @@ void main() {
}, variant: TargetPlatformVariant.mobile()); }, variant: TargetPlatformVariant.mobile());
testWidgets('Mouse events change initial focus highlight mode on desktop.', (WidgetTester tester) async { testWidgets('Mouse events change initial focus highlight mode on desktop.', (WidgetTester tester) async {
expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional)); expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional));
RendererBinding.instance.initMouseTracker(); // Clear out the mouse state. RendererBinding.instance!.initMouseTracker(); // Clear out the mouse state.
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 0); final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 0);
addTearDown(gesture.removePointer); addTearDown(gesture.removePointer);
await gesture.moveTo(Offset.zero); await gesture.moveTo(Offset.zero);
...@@ -952,7 +950,7 @@ void main() { ...@@ -952,7 +950,7 @@ void main() {
testWidgets('Events change focus highlight mode.', (WidgetTester tester) async { testWidgets('Events change focus highlight mode.', (WidgetTester tester) async {
await setupWidget(tester); await setupWidget(tester);
int callCount = 0; int callCount = 0;
FocusHighlightMode lastMode; FocusHighlightMode? lastMode;
void handleModeChange(FocusHighlightMode mode) { void handleModeChange(FocusHighlightMode mode) {
lastMode = mode; lastMode = mode;
callCount++; callCount++;
......
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