Unverified Commit 7ce0dce2 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Migrate even more Material framework tests to null safety. (#67849)

parent fda735cf
...@@ -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';
...@@ -27,7 +25,7 @@ void main() { ...@@ -27,7 +25,7 @@ void main() {
), ),
), ),
)); ));
final RenderBox box = inner.currentContext.findRenderObject() as RenderBox; final RenderBox box = inner.currentContext!.findRenderObject()! as RenderBox;
expect(box.size, equals(const Size(50.0, 25.0))); expect(box.size, equals(const Size(50.0, 25.0)));
expect(box.localToGlobal(Offset.zero), equals(const Offset(25.0, 37.5))); expect(box.localToGlobal(Offset.zero), equals(const Offset(25.0, 37.5)));
}); });
...@@ -43,7 +41,7 @@ void main() { ...@@ -43,7 +41,7 @@ void main() {
child: Placeholder(key: inner), child: Placeholder(key: inner),
), ),
)); ));
final RenderBox box = inner.currentContext.findRenderObject() as RenderBox; final RenderBox box = inner.currentContext!.findRenderObject()! as RenderBox;
expect(box.size, equals(const Size(400.0, 300.0))); expect(box.size, equals(const Size(400.0, 300.0)));
expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(800.0 - 400.0 / 2.0, 0.0 + 300.0 / 2.0))); expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(800.0 - 400.0 / 2.0, 0.0 + 300.0 / 2.0)));
}); });
...@@ -59,7 +57,7 @@ void main() { ...@@ -59,7 +57,7 @@ void main() {
child: Placeholder(key: inner), child: Placeholder(key: inner),
), ),
)); ));
final RenderBox box = inner.currentContext.findRenderObject() as RenderBox; final RenderBox box = inner.currentContext!.findRenderObject()! as RenderBox;
expect(box.size, equals(const Size(400.0, 300.0))); expect(box.size, equals(const Size(400.0, 300.0)));
expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(0.0 + 400.0 / 2.0, 0.0 + 300.0 / 2.0))); expect(box.localToGlobal(box.size.center(Offset.zero)), equals(const Offset(0.0 + 400.0 / 2.0, 0.0 + 300.0 / 2.0)));
}); });
...@@ -85,7 +83,7 @@ void main() { ...@@ -85,7 +83,7 @@ void main() {
), ),
), ),
)); ));
final RenderBox box = inner.currentContext.findRenderObject() as RenderBox; final RenderBox box = inner.currentContext!.findRenderObject()! as RenderBox;
expect(box.size, equals(const Size(50.0, 25.0))); expect(box.size, equals(const Size(50.0, 25.0)));
expect(box.localToGlobal(Offset.zero), equals(const Offset(25.0, 37.5))); expect(box.localToGlobal(Offset.zero), equals(const Offset(25.0, 37.5)));
}); });
......
...@@ -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';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -14,7 +12,7 @@ void main() { ...@@ -14,7 +12,7 @@ void main() {
testWidgets('Uncontested scrolls start immediately', (WidgetTester tester) async { testWidgets('Uncontested scrolls start immediately', (WidgetTester tester) async {
bool didStartDrag = false; bool didStartDrag = false;
double updatedDragDelta; double? updatedDragDelta;
bool didEndDrag = false; bool didEndDrag = false;
final Widget widget = GestureDetector( final Widget widget = GestureDetector(
...@@ -69,7 +67,7 @@ void main() { ...@@ -69,7 +67,7 @@ void main() {
final Widget widget = GestureDetector( final Widget widget = GestureDetector(
dragStartBehavior: DragStartBehavior.down, dragStartBehavior: DragStartBehavior.down,
onVerticalDragUpdate: (DragUpdateDetails details) { dragDistance += details.primaryDelta; }, onVerticalDragUpdate: (DragUpdateDetails details) { dragDistance += details.primaryDelta ?? 0; },
onVerticalDragEnd: (DragEndDetails details) { gestureCount += 1; }, onVerticalDragEnd: (DragEndDetails details) { gestureCount += 1; },
onHorizontalDragUpdate: (DragUpdateDetails details) { fail('gesture should not match'); }, onHorizontalDragUpdate: (DragUpdateDetails details) { fail('gesture should not match'); },
onHorizontalDragEnd: (DragEndDetails details) { fail('gesture should not match'); }, onHorizontalDragEnd: (DragEndDetails details) { fail('gesture should not match'); },
...@@ -95,7 +93,7 @@ void main() { ...@@ -95,7 +93,7 @@ void main() {
testWidgets("Pan doesn't crash", (WidgetTester tester) async { testWidgets("Pan doesn't crash", (WidgetTester tester) async {
bool didStartPan = false; bool didStartPan = false;
Offset panDelta; Offset? panDelta;
bool didEndPan = false; bool didEndPan = false;
await tester.pumpWidget( await tester.pumpWidget(
...@@ -104,7 +102,7 @@ void main() { ...@@ -104,7 +102,7 @@ void main() {
didStartPan = true; didStartPan = true;
}, },
onPanUpdate: (DragUpdateDetails details) { onPanUpdate: (DragUpdateDetails details) {
panDelta = panDelta == null ? details.delta : panDelta + details.delta; panDelta = (panDelta ?? Offset.zero) + details.delta;
}, },
onPanEnd: (DragEndDetails details) { onPanEnd: (DragEndDetails details) {
didEndPan = true; didEndPan = true;
...@@ -122,8 +120,8 @@ void main() { ...@@ -122,8 +120,8 @@ void main() {
await tester.dragFrom(const Offset(10.0, 10.0), const Offset(20.0, 30.0)); await tester.dragFrom(const Offset(10.0, 10.0), const Offset(20.0, 30.0));
expect(didStartPan, isTrue); expect(didStartPan, isTrue);
expect(panDelta.dx, 20.0); expect(panDelta!.dx, 20.0);
expect(panDelta.dy, 30.0); expect(panDelta!.dy, 30.0);
expect(didEndPan, isTrue); expect(didEndPan, isTrue);
}); });
...@@ -141,7 +139,7 @@ void main() { ...@@ -141,7 +139,7 @@ void main() {
bool didReceivePointerDown; bool didReceivePointerDown;
bool didTap; bool didTap;
Future<void> pumpWidgetTree(HitTestBehavior behavior) { Future<void> pumpWidgetTree(HitTestBehavior? behavior) {
return tester.pumpWidget( return tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -732,7 +730,7 @@ void main() { ...@@ -732,7 +730,7 @@ void main() {
await tester.pumpWidget(RawGestureDetector( await tester.pumpWidget(RawGestureDetector(
key: key, key: key,
)); ));
key.currentState.debugFillProperties(builder); key.currentState!.debugFillProperties(builder);
final List<String> description = builder.properties final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
...@@ -767,7 +765,7 @@ void main() { ...@@ -767,7 +765,7 @@ void main() {
child: Container(), child: Container(),
semantics: _EmptySemanticsGestureDelegate(), semantics: _EmptySemanticsGestureDelegate(),
)); ));
key.currentState.debugFillProperties(builder); key.currentState!.debugFillProperties(builder);
final List<String> description = builder.properties final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
...@@ -791,7 +789,7 @@ void main() { ...@@ -791,7 +789,7 @@ void main() {
semantics: _EmptySemanticsGestureDelegate(), semantics: _EmptySemanticsGestureDelegate(),
excludeFromSemantics: true, excludeFromSemantics: true,
)); ));
key.currentState.debugFillProperties(builder); key.currentState!.debugFillProperties(builder);
final List<String> description = builder.properties final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
...@@ -806,13 +804,12 @@ void main() { ...@@ -806,13 +804,12 @@ void main() {
group('error control test', () { group('error control test', () {
test('constructor redundant pan and scale', () { test('constructor redundant pan and scale', () {
FlutterError error; late FlutterError error;
try { try {
GestureDetector(onScaleStart: (_) {}, onPanStart: (_) {},); GestureDetector(onScaleStart: (_) {}, onPanStart: (_) {},);
} on FlutterError catch (e) { } on FlutterError catch (e) {
error = e; error = e;
} finally { } finally {
expect(error, isNotNull);
expect( expect(
error.toStringDeep(), error.toStringDeep(),
'FlutterError\n' 'FlutterError\n'
...@@ -832,7 +829,7 @@ void main() { ...@@ -832,7 +829,7 @@ void main() {
}); });
test('constructor duplicate drag recognizer', () { test('constructor duplicate drag recognizer', () {
FlutterError error; late FlutterError error;
try { try {
GestureDetector( GestureDetector(
onVerticalDragStart: (_) {}, onVerticalDragStart: (_) {},
...@@ -842,7 +839,6 @@ void main() { ...@@ -842,7 +839,6 @@ void main() {
} on FlutterError catch (e) { } on FlutterError catch (e) {
error = e; error = e;
} finally { } finally {
expect(error, isNotNull);
expect( expect(
error.toStringDeep(), error.toStringDeep(),
'FlutterError\n' 'FlutterError\n'
...@@ -868,14 +864,13 @@ void main() { ...@@ -868,14 +864,13 @@ void main() {
), ),
), ),
); );
FlutterError error; late FlutterError error;
try { try {
key.currentState.replaceGestureRecognizers( key.currentState!.replaceGestureRecognizers(
<Type, GestureRecognizerFactory>{}); <Type, GestureRecognizerFactory>{});
} on FlutterError catch (e) { } on FlutterError catch (e) {
error = e; error = e;
} finally { } finally {
expect(error, isNotNull);
expect(error.diagnostics.last.level, DiagnosticLevel.hint); expect(error.diagnostics.last.level, DiagnosticLevel.hint);
expect( expect(
error.diagnostics.last.toStringDeep(), error.diagnostics.last.toStringDeep(),
...@@ -913,8 +908,8 @@ class _EmptySemanticsGestureDelegate extends SemanticsGestureDelegate { ...@@ -913,8 +908,8 @@ class _EmptySemanticsGestureDelegate extends SemanticsGestureDelegate {
/// A [TestVariant] that runs tests multiple times with different buttons. /// A [TestVariant] that runs tests multiple times with different buttons.
class ButtonVariant extends TestVariant<int> { class ButtonVariant extends TestVariant<int> {
const ButtonVariant({ const ButtonVariant({
@required this.values, required this.values,
@required this.descriptions, required this.descriptions,
}) : assert(values.length != 0); // ignore: prefer_is_empty }) : assert(values.length != 0); // ignore: prefer_is_empty
@override @override
...@@ -922,12 +917,12 @@ class ButtonVariant extends TestVariant<int> { ...@@ -922,12 +917,12 @@ class ButtonVariant extends TestVariant<int> {
final Map<int, String> descriptions; final Map<int, String> descriptions;
static int button; static int button = 0;
@override @override
String describeValue(int value) { String describeValue(int value) {
assert(descriptions.containsKey(value), 'Unknown button'); assert(descriptions.containsKey(value), 'Unknown button');
return descriptions[value]; return descriptions[value]!;
} }
@override @override
......
...@@ -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';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.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_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -61,7 +59,7 @@ void main() { ...@@ -61,7 +59,7 @@ void main() {
}); });
testWidgets('GlobalKey children of two nodes', (WidgetTester tester) async { testWidgets('GlobalKey children of two nodes', (WidgetTester tester) async {
StateSetter nestedSetState; late StateSetter nestedSetState;
bool flag = false; bool flag = false;
await tester.pumpWidget(Stack( await tester.pumpWidget(Stack(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -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';
...@@ -17,7 +15,7 @@ class Item { ...@@ -17,7 +15,7 @@ class Item {
List<Item> items = <Item>[Item(), Item()]; List<Item> items = <Item>[Item(), Item()];
class StatefulLeaf extends StatefulWidget { class StatefulLeaf extends StatefulWidget {
const StatefulLeaf({ GlobalKey key }) : super(key: key); const StatefulLeaf({ GlobalKey? key }) : super(key: key);
@override @override
StatefulLeafState createState() => StatefulLeafState(); StatefulLeafState createState() => StatefulLeafState();
...@@ -31,7 +29,7 @@ class StatefulLeafState extends State<StatefulLeaf> { ...@@ -31,7 +29,7 @@ class StatefulLeafState extends State<StatefulLeaf> {
} }
class KeyedWrapper extends StatelessWidget { class KeyedWrapper extends StatelessWidget {
const KeyedWrapper(this.key1, this.key2, { Key key }) : super(key: key); const KeyedWrapper(this.key1, this.key2, { Key? key }) : super(key: key);
final Key key1; final Key key1;
final GlobalKey key2; final GlobalKey key2;
......
...@@ -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';
......
...@@ -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/widgets.dart'; import 'package:flutter/widgets.dart';
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';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -578,8 +576,7 @@ void main() { ...@@ -578,8 +576,7 @@ void main() {
itemCount: 1000, itemCount: 1000,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
counters[index] ??= 0; counters[index] = (counters[index] ?? 0) + 1;
counters[index] += 1;
return SizedBox( return SizedBox(
key: ValueKey<int>(index), key: ValueKey<int>(index),
width: 200, width: 200,
......
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