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