Unverified Commit aaaf3741 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate last batch of tests (#68163)

parent bf6460f9
...@@ -39,7 +39,7 @@ class FractionalOffsetTween extends Tween<FractionalOffset?> { ...@@ -39,7 +39,7 @@ class FractionalOffsetTween extends Tween<FractionalOffset?> {
/// ///
/// * [AlignmentGeometryTween], which interpolates between two /// * [AlignmentGeometryTween], which interpolates between two
/// [AlignmentGeometry] objects. /// [AlignmentGeometry] objects.
class AlignmentTween extends Tween<Alignment?> { class AlignmentTween extends Tween<Alignment> {
/// Creates a fractional offset tween. /// Creates a fractional offset tween.
/// ///
/// The [begin] and [end] properties may be null; the null value /// The [begin] and [end] properties may be null; the null value
...@@ -49,7 +49,7 @@ class AlignmentTween extends Tween<Alignment?> { ...@@ -49,7 +49,7 @@ class AlignmentTween extends Tween<Alignment?> {
/// Returns the value this variable has at the given animation clock value. /// Returns the value this variable has at the given animation clock value.
@override @override
Alignment? lerp(double t) => Alignment.lerp(begin, end, t); Alignment lerp(double t) => Alignment.lerp(begin, end, t)!;
} }
/// An interpolation between two [AlignmentGeometry]. /// An interpolation between two [AlignmentGeometry].
......
...@@ -16,7 +16,7 @@ import 'framework.dart'; ...@@ -16,7 +16,7 @@ import 'framework.dart';
/// ///
/// * [ValueListenableBuilder], a widget which invokes this builder each time /// * [ValueListenableBuilder], a widget which invokes this builder each time
/// a [ValueListenable] changes value. /// a [ValueListenable] changes value.
typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T? value, Widget? child); typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T value, Widget? child);
/// A widget whose content stays synced with a [ValueListenable]. /// A widget whose content stays synced with a [ValueListenable].
/// ///
...@@ -153,7 +153,7 @@ class ValueListenableBuilder<T> extends StatefulWidget { ...@@ -153,7 +153,7 @@ class ValueListenableBuilder<T> extends StatefulWidget {
} }
class _ValueListenableBuilderState<T> extends State<ValueListenableBuilder<T>> { class _ValueListenableBuilderState<T> extends State<ValueListenableBuilder<T>> {
T? value; late T value;
@override @override
void initState() { void initState() {
......
...@@ -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/material.dart'; import 'package:flutter/material.dart';
...@@ -50,7 +48,7 @@ void main() { ...@@ -50,7 +48,7 @@ void main() {
), ),
); );
AnimationController controller; late AnimationController controller;
setUp(() { setUp(() {
controller = AnimationController(vsync: const TestVSync()); controller = AnimationController(vsync: const TestVSync());
...@@ -71,9 +69,9 @@ void main() { ...@@ -71,9 +69,9 @@ void main() {
BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration;
expect(actualDecoration.color, const Color(0xFFFFFFFF)); expect(actualDecoration.color, const Color(0xFFFFFFFF));
expect(actualDecoration.boxShadow[0].blurRadius, 10.0); expect(actualDecoration.boxShadow![0].blurRadius, 10.0);
expect(actualDecoration.boxShadow[0].spreadRadius, 4.0); expect(actualDecoration.boxShadow![0].spreadRadius, 4.0);
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));
controller.value = 0.5; controller.value = 0.5;
...@@ -83,16 +81,16 @@ void main() { ...@@ -83,16 +81,16 @@ void main() {
expect(actualDecoration.color, const Color(0xFF7F7F7F)); expect(actualDecoration.color, const Color(0xFF7F7F7F));
expect(actualDecoration.border, isA<Border>()); expect(actualDecoration.border, isA<Border>());
final Border border = actualDecoration.border as Border; final Border border = actualDecoration.border! as Border;
expect(border.left.width, 2.5); expect(border.left.width, 2.5);
expect(border.left.style, BorderStyle.solid); expect(border.left.style, BorderStyle.solid);
expect(border.left.color, const Color(0xFF101010)); expect(border.left.color, const Color(0xFF101010));
expect(actualDecoration.borderRadius, BorderRadius.circular(5.0)); expect(actualDecoration.borderRadius, BorderRadius.circular(5.0));
expect(actualDecoration.shape, BoxShape.rectangle); expect(actualDecoration.shape, BoxShape.rectangle);
expect(actualDecoration.boxShadow[0].blurRadius, 5.0); expect(actualDecoration.boxShadow![0].blurRadius, 5.0);
expect(actualDecoration.boxShadow[0].spreadRadius, 2.0); expect(actualDecoration.boxShadow![0].spreadRadius, 2.0);
// Scaling a shadow doesn't change the color. // Scaling a shadow doesn't change the color.
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));
controller.value = 1.0; controller.value = 1.0;
...@@ -126,9 +124,9 @@ void main() { ...@@ -126,9 +124,9 @@ void main() {
BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration;
expect(actualDecoration.color, const Color(0xFFFFFFFF)); expect(actualDecoration.color, const Color(0xFFFFFFFF));
expect(actualDecoration.boxShadow[0].blurRadius, 10.0); expect(actualDecoration.boxShadow![0].blurRadius, 10.0);
expect(actualDecoration.boxShadow[0].spreadRadius, 4.0); expect(actualDecoration.boxShadow![0].spreadRadius, 4.0);
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));
controller.value = 0.5; controller.value = 0.5;
...@@ -140,16 +138,16 @@ void main() { ...@@ -140,16 +138,16 @@ void main() {
// tween's end values given the easeOut curve. // tween's end values given the easeOut curve.
expect(actualDecoration.color, const Color(0xFF505050)); expect(actualDecoration.color, const Color(0xFF505050));
expect(actualDecoration.border, isA<Border>()); expect(actualDecoration.border, isA<Border>());
final Border border = actualDecoration.border as Border; final Border border = actualDecoration.border! as Border;
expect(border.left.width, moreOrLessEquals(1.9, epsilon: 0.1)); expect(border.left.width, moreOrLessEquals(1.9, epsilon: 0.1));
expect(border.left.style, BorderStyle.solid); expect(border.left.style, BorderStyle.solid);
expect(border.left.color, const Color(0xFF151515)); expect(border.left.color, const Color(0xFF151515));
expect(actualDecoration.borderRadius.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1)); expect(actualDecoration.borderRadius!.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1));
expect(actualDecoration.shape, BoxShape.rectangle); expect(actualDecoration.shape, BoxShape.rectangle);
expect(actualDecoration.boxShadow[0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1)); expect(actualDecoration.boxShadow![0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1));
expect(actualDecoration.boxShadow[0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1)); expect(actualDecoration.boxShadow![0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1));
// Scaling a shadow doesn't change the color. // Scaling a shadow doesn't change the color.
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));
}); });
}); });
......
...@@ -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';
...@@ -15,7 +13,7 @@ void main() { ...@@ -15,7 +13,7 @@ void main() {
TweenAnimationBuilder<int>( TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
tween: IntTween(begin: 10, end: 110), tween: IntTween(begin: 10, end: 110),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -46,7 +44,7 @@ void main() { ...@@ -46,7 +44,7 @@ void main() {
TweenAnimationBuilder<int>( TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
tween: IntTween(end: 100), tween: IntTween(end: 100),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -70,7 +68,7 @@ void main() { ...@@ -70,7 +68,7 @@ void main() {
TweenAnimationBuilder<int>( TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
tween: IntTween(begin: 100, end: 100), tween: IntTween(begin: 100, end: 100),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -88,11 +86,11 @@ void main() { ...@@ -88,11 +86,11 @@ void main() {
testWidgets('Replace tween animates new tween', (WidgetTester tester) async { testWidgets('Replace tween animates new tween', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) { Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
tween: tween, tween: tween,
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -116,12 +114,12 @@ void main() { ...@@ -116,12 +114,12 @@ void main() {
testWidgets('Curve is respected', (WidgetTester tester) async { testWidgets('Curve is respected', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween, Curve curve}) { Widget buildWidget({required IntTween tween, required Curve curve}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
tween: tween, tween: tween,
curve: curve, curve: curve,
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -146,11 +144,11 @@ void main() { ...@@ -146,11 +144,11 @@ void main() {
testWidgets('Duration is respected', (WidgetTester tester) async { testWidgets('Duration is respected', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween, Duration duration}) { Widget buildWidget({required IntTween tween, required Duration duration}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: tween, tween: tween,
duration: duration, duration: duration,
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -179,8 +177,8 @@ void main() { ...@@ -179,8 +177,8 @@ void main() {
child: TweenAnimationBuilder<int>( child: TweenAnimationBuilder<int>(
tween: IntTween(begin: 0, end: 100), tween: IntTween(begin: 0, end: 100),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
return child; return child!;
}, },
child: const Text('Hello World'), child: const Text('Hello World'),
), ),
...@@ -193,11 +191,11 @@ void main() { ...@@ -193,11 +191,11 @@ void main() {
group('Change tween gapless while', () { group('Change tween gapless while', () {
testWidgets('running forward', (WidgetTester tester) async { testWidgets('running forward', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) { Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: tween, tween: tween,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -228,11 +226,11 @@ void main() { ...@@ -228,11 +226,11 @@ void main() {
testWidgets('running forward and then reverse with same tween instance', (WidgetTester tester) async { testWidgets('running forward and then reverse with same tween instance', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) { Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: tween, tween: tween,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -258,11 +256,11 @@ void main() { ...@@ -258,11 +256,11 @@ void main() {
testWidgets('Changing tween while gapless tween change is in progress', (WidgetTester tester) async { testWidgets('Changing tween while gapless tween change is in progress', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) { Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: tween, tween: tween,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -298,12 +296,12 @@ void main() { ...@@ -298,12 +296,12 @@ void main() {
testWidgets('Changing curve while no animation is running does not trigger animation', (WidgetTester tester) async { testWidgets('Changing curve while no animation is running does not trigger animation', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({Curve curve}) { Widget buildWidget({required Curve curve}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: IntTween(begin: 0, end: 100), tween: IntTween(begin: 0, end: 100),
curve: curve, curve: curve,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -327,11 +325,11 @@ void main() { ...@@ -327,11 +325,11 @@ void main() {
testWidgets('Setting same tween and direction does not trigger animation', (WidgetTester tester) async { testWidgets('Setting same tween and direction does not trigger animation', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) { Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: tween, tween: tween,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
...@@ -356,11 +354,11 @@ void main() { ...@@ -356,11 +354,11 @@ void main() {
testWidgets('Setting same tween and direction while gapless animation is in progress works', (WidgetTester tester) async { testWidgets('Setting same tween and direction while gapless animation is in progress works', (WidgetTester tester) async {
final List<int> values = <int>[]; final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) { Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>( return TweenAnimationBuilder<int>(
tween: tween, tween: tween,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) { builder: (BuildContext context, int i, Widget? child) {
values.add(i); values.add(i);
return const Placeholder(); return const Placeholder();
}, },
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
// 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';
class TestUniqueWidget extends UniqueWidget<TestUniqueWidgetState> { class TestUniqueWidget extends UniqueWidget<TestUniqueWidgetState> {
const TestUniqueWidget({ GlobalKey<TestUniqueWidgetState> key }) : super(key: key); const TestUniqueWidget({ required GlobalKey<TestUniqueWidgetState> key }) : super(key: key);
@override @override
TestUniqueWidgetState createState() => TestUniqueWidgetState(); TestUniqueWidgetState createState() => TestUniqueWidgetState();
...@@ -25,7 +23,7 @@ void main() { ...@@ -25,7 +23,7 @@ void main() {
await tester.pumpWidget(widget); await tester.pumpWidget(widget);
final TestUniqueWidgetState state = widget.currentState; final TestUniqueWidgetState state = widget.currentState!;
expect(state, isNotNull); expect(state, isNotNull);
......
...@@ -2,24 +2,22 @@ ...@@ -2,24 +2,22 @@
// 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/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
void main() { void main() {
SpyStringValueNotifier valueListenable; late SpyStringValueNotifier valueListenable;
Widget textBuilderUnderTest; late Widget textBuilderUnderTest;
Widget builderForValueListenable( Widget builderForValueListenable(
ValueListenable<String> valueListenable, ValueListenable<String?> valueListenable,
) { ) {
return Directionality( return Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: ValueListenableBuilder<String>( child: ValueListenableBuilder<String?>(
valueListenable: valueListenable, valueListenable: valueListenable,
builder: (BuildContext context, String value, Widget child) { builder: (BuildContext context, String? value, Widget? child) {
if (value == null) if (value == null)
return const Placeholder(); return const Placeholder();
return Text(value); return Text(value);
...@@ -67,7 +65,7 @@ void main() { ...@@ -67,7 +65,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(find.text('Gilfoyle'), findsOneWidget); expect(find.text('Gilfoyle'), findsOneWidget);
final ValueListenable<String> differentListenable = final ValueListenable<String?> differentListenable =
SpyStringValueNotifier('Hendricks'); SpyStringValueNotifier('Hendricks');
await tester.pumpWidget(builderForValueListenable(differentListenable)); await tester.pumpWidget(builderForValueListenable(differentListenable));
...@@ -83,7 +81,7 @@ void main() { ...@@ -83,7 +81,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(find.text('Gilfoyle'), findsOneWidget); expect(find.text('Gilfoyle'), findsOneWidget);
final ValueListenable<String> differentListenable = final ValueListenable<String?> differentListenable =
SpyStringValueNotifier('Hendricks'); SpyStringValueNotifier('Hendricks');
await tester.pumpWidget(builderForValueListenable(differentListenable)); await tester.pumpWidget(builderForValueListenable(differentListenable));
...@@ -113,8 +111,8 @@ void main() { ...@@ -113,8 +111,8 @@ void main() {
}); });
} }
class SpyStringValueNotifier extends ValueNotifier<String> { class SpyStringValueNotifier extends ValueNotifier<String?> {
SpyStringValueNotifier(String initialValue) : super(initialValue); SpyStringValueNotifier(String? initialValue) : super(initialValue);
/// Override for test visibility only. /// Override for test visibility only.
@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/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -11,7 +9,7 @@ import '../rendering/mock_canvas.dart'; ...@@ -11,7 +9,7 @@ import '../rendering/mock_canvas.dart';
import 'semantics_tester.dart'; import 'semantics_tester.dart';
class TestState extends StatefulWidget { class TestState extends StatefulWidget {
const TestState({ Key key, this.child, this.log }) : super(key: key); const TestState({ Key? key, required this.child, required this.log }) : super(key: key);
final Widget child; final Widget child;
final List<String> log; final List<String> log;
@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/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -25,8 +23,8 @@ class StructuredErrorTestService extends TestWidgetInspectorService { ...@@ -25,8 +23,8 @@ class StructuredErrorTestService extends TestWidgetInspectorService {
static void runTests() { static void runTests() {
final StructuredErrorTestService service = StructuredErrorTestService(); final StructuredErrorTestService service = StructuredErrorTestService();
WidgetInspectorService.instance = service; WidgetInspectorService.instance = service;
FlutterExceptionHandler testHandler; FlutterExceptionHandler? testHandler;
FlutterExceptionHandler inspectorServiceErrorHandler; FlutterExceptionHandler? inspectorServiceErrorHandler;
setUpAll(() { setUpAll(() {
inspectorServiceErrorHandler = FlutterError.onError; inspectorServiceErrorHandler = FlutterError.onError;
...@@ -42,7 +40,7 @@ class StructuredErrorTestService extends TestWidgetInspectorService { ...@@ -42,7 +40,7 @@ class StructuredErrorTestService extends TestWidgetInspectorService {
// what it was after WidgetInspectorService::initServiceExtensions ran. // what it was after WidgetInspectorService::initServiceExtensions ran.
FlutterError.onError = inspectorServiceErrorHandler; FlutterError.onError = inspectorServiceErrorHandler;
List<Map<Object, Object>> flutterErrorEvents = List<Map<Object, Object?>> flutterErrorEvents =
service.getEventsDispatched('Flutter.Error'); service.getEventsDispatched('Flutter.Error');
expect(flutterErrorEvents, hasLength(0)); expect(flutterErrorEvents, hasLength(0));
......
...@@ -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:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
...@@ -16,41 +14,41 @@ void main() { ...@@ -16,41 +14,41 @@ void main() {
StructureErrorTestWidgetInspectorService.runTests(); StructureErrorTestWidgetInspectorService.runTests();
} }
typedef InspectorServiceExtensionCallback = FutureOr<Map<String, Object>> Function(Map<String, String> parameters); typedef InspectorServiceExtensionCallback = FutureOr<Map<String, Object?>> Function(Map<String, String> parameters);
class StructureErrorTestWidgetInspectorService extends Object with WidgetInspectorService { class StructureErrorTestWidgetInspectorService extends Object with WidgetInspectorService {
final Map<String, InspectorServiceExtensionCallback> extensions = <String, InspectorServiceExtensionCallback>{}; final Map<String, InspectorServiceExtensionCallback> extensions = <String, InspectorServiceExtensionCallback>{};
final Map<String, List<Map<Object, Object>>> eventsDispatched = <String, List<Map<Object, Object>>>{}; final Map<String, List<Map<Object, Object?>>> eventsDispatched = <String, List<Map<Object, Object?>>>{};
@override @override
void registerServiceExtension({ void registerServiceExtension({
@required String name, required String name,
@required FutureOr<Map<String, Object>> callback(Map<String, String> parameters), required FutureOr<Map<String, Object?>> callback(Map<String, String> parameters),
}) { }) {
assert(!extensions.containsKey(name)); assert(!extensions.containsKey(name));
extensions[name] = callback; extensions[name] = callback;
} }
@override @override
void postEvent(String eventKind, Map<Object, Object> eventData) { void postEvent(String eventKind, Map<Object, Object?> eventData) {
getEventsDispatched(eventKind).add(eventData); getEventsDispatched(eventKind).add(eventData);
} }
List<Map<Object, Object>> getEventsDispatched(String eventKind) { List<Map<Object, Object?>> getEventsDispatched(String eventKind) {
return eventsDispatched.putIfAbsent(eventKind, () => <Map<Object, Object>>[]); return eventsDispatched.putIfAbsent(eventKind, () => <Map<Object, Object?>>[]);
} }
Iterable<Map<Object, Object>> getServiceExtensionStateChangedEvents(String extensionName) { Iterable<Map<Object, Object?>> getServiceExtensionStateChangedEvents(String extensionName) {
return getEventsDispatched('Flutter.ServiceExtensionStateChanged') return getEventsDispatched('Flutter.ServiceExtensionStateChanged')
.where((Map<Object, Object> event) => event['extension'] == extensionName); .where((Map<Object, Object?> event) => event['extension'] == extensionName);
} }
Future<String> testBoolExtension(String name, Map<String, String> arguments) async { Future<String> testBoolExtension(String name, Map<String, String> arguments) async {
expect(extensions, contains(name)); expect(extensions, contains(name));
// Encode and decode to JSON to match behavior using a real service // Encode and decode to JSON to match behavior using a real service
// extension where only JSON is allowed. // extension where only JSON is allowed.
return json.decode(json.encode(await extensions[name](arguments)))['enabled'] as String; return json.decode(json.encode(await extensions[name]!(arguments)))['enabled'] as String;
} }
...@@ -59,9 +57,9 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect ...@@ -59,9 +57,9 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect
WidgetInspectorService.instance = service; WidgetInspectorService.instance = service;
test('ext.flutter.inspector.structuredErrors still report error to original on error', () async { test('ext.flutter.inspector.structuredErrors still report error to original on error', () async {
final FlutterExceptionHandler oldHandler = FlutterError.onError; final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterErrorDetails actualError; late FlutterErrorDetails actualError;
// Creates a spy onError. This spy needs to be set before widgets binding // Creates a spy onError. This spy needs to be set before widgets binding
// initializes. // initializes.
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.onError = (FlutterErrorDetails details) {
......
...@@ -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';
......
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