From aaaf37418b2a22bb4a63c78ace3686061f7a8bc2 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 14 Oct 2020 22:52:05 -0700 Subject: [PATCH] Migrate last batch of tests (#68163) --- .../flutter/lib/src/rendering/tweens.dart | 4 +- .../src/widgets/value_listenable_builder.dart | 4 +- .../test/widgets/transitions_test.dart | 34 +- .../widgets/tween_animation_builder_test.dart | 48 +- .../test/widgets/unique_widget_test.dart | 6 +- .../value_listenable_builder_test.dart | 20 +- .../flutter/test/widgets/visibility_test.dart | 4 +- ...ector_init_with_structured_error_test.dart | 8 +- ...widget_inspector_structure_error_test.dart | 28 +- .../test/widgets/widget_inspector_test.dart | 446 +++++++++--------- packages/flutter/test/widgets/wrap_test.dart | 2 - 11 files changed, 293 insertions(+), 311 deletions(-) diff --git a/packages/flutter/lib/src/rendering/tweens.dart b/packages/flutter/lib/src/rendering/tweens.dart index 5d2e9ade68..f8d59e2d51 100644 --- a/packages/flutter/lib/src/rendering/tweens.dart +++ b/packages/flutter/lib/src/rendering/tweens.dart @@ -39,7 +39,7 @@ class FractionalOffsetTween extends Tween { /// /// * [AlignmentGeometryTween], which interpolates between two /// [AlignmentGeometry] objects. -class AlignmentTween extends Tween { +class AlignmentTween extends Tween { /// Creates a fractional offset tween. /// /// The [begin] and [end] properties may be null; the null value @@ -49,7 +49,7 @@ class AlignmentTween extends Tween { /// Returns the value this variable has at the given animation clock value. @override - Alignment? lerp(double t) => Alignment.lerp(begin, end, t); + Alignment lerp(double t) => Alignment.lerp(begin, end, t)!; } /// An interpolation between two [AlignmentGeometry]. diff --git a/packages/flutter/lib/src/widgets/value_listenable_builder.dart b/packages/flutter/lib/src/widgets/value_listenable_builder.dart index 86599db865..9a2c43c92f 100644 --- a/packages/flutter/lib/src/widgets/value_listenable_builder.dart +++ b/packages/flutter/lib/src/widgets/value_listenable_builder.dart @@ -16,7 +16,7 @@ import 'framework.dart'; /// /// * [ValueListenableBuilder], a widget which invokes this builder each time /// a [ValueListenable] changes value. -typedef ValueWidgetBuilder = Widget Function(BuildContext context, T? value, Widget? child); +typedef ValueWidgetBuilder = Widget Function(BuildContext context, T value, Widget? child); /// A widget whose content stays synced with a [ValueListenable]. /// @@ -153,7 +153,7 @@ class ValueListenableBuilder extends StatefulWidget { } class _ValueListenableBuilderState extends State> { - T? value; + late T value; @override void initState() { diff --git a/packages/flutter/test/widgets/transitions_test.dart b/packages/flutter/test/widgets/transitions_test.dart index 458967ec60..4f1e5efa39 100644 --- a/packages/flutter/test/widgets/transitions_test.dart +++ b/packages/flutter/test/widgets/transitions_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 'dart:math' as math; import 'package:flutter/material.dart'; @@ -50,7 +48,7 @@ void main() { ), ); - AnimationController controller; + late AnimationController controller; setUp(() { controller = AnimationController(vsync: const TestVSync()); @@ -71,9 +69,9 @@ void main() { BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; expect(actualDecoration.color, const Color(0xFFFFFFFF)); - expect(actualDecoration.boxShadow[0].blurRadius, 10.0); - expect(actualDecoration.boxShadow[0].spreadRadius, 4.0); - expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); + expect(actualDecoration.boxShadow![0].blurRadius, 10.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 4.0); + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); controller.value = 0.5; @@ -83,16 +81,16 @@ void main() { expect(actualDecoration.color, const Color(0xFF7F7F7F)); expect(actualDecoration.border, isA()); - final Border border = actualDecoration.border as Border; + final Border border = actualDecoration.border! as Border; expect(border.left.width, 2.5); expect(border.left.style, BorderStyle.solid); expect(border.left.color, const Color(0xFF101010)); expect(actualDecoration.borderRadius, BorderRadius.circular(5.0)); expect(actualDecoration.shape, BoxShape.rectangle); - expect(actualDecoration.boxShadow[0].blurRadius, 5.0); - expect(actualDecoration.boxShadow[0].spreadRadius, 2.0); + expect(actualDecoration.boxShadow![0].blurRadius, 5.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 2.0); // 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; @@ -126,9 +124,9 @@ void main() { BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration; expect(actualDecoration.color, const Color(0xFFFFFFFF)); - expect(actualDecoration.boxShadow[0].blurRadius, 10.0); - expect(actualDecoration.boxShadow[0].spreadRadius, 4.0); - expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); + expect(actualDecoration.boxShadow![0].blurRadius, 10.0); + expect(actualDecoration.boxShadow![0].spreadRadius, 4.0); + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); controller.value = 0.5; @@ -140,16 +138,16 @@ void main() { // tween's end values given the easeOut curve. expect(actualDecoration.color, const Color(0xFF505050)); expect(actualDecoration.border, isA()); - 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.style, BorderStyle.solid); 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.boxShadow[0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1)); - expect(actualDecoration.boxShadow[0].spreadRadius, moreOrLessEquals(1.2, 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)); // Scaling a shadow doesn't change the color. - expect(actualDecoration.boxShadow[0].color, const Color(0x66000000)); + expect(actualDecoration.boxShadow![0].color, const Color(0x66000000)); }); }); diff --git a/packages/flutter/test/widgets/tween_animation_builder_test.dart b/packages/flutter/test/widgets/tween_animation_builder_test.dart index 44beab208a..830ba44882 100644 --- a/packages/flutter/test/widgets/tween_animation_builder_test.dart +++ b/packages/flutter/test/widgets/tween_animation_builder_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'; @@ -15,7 +13,7 @@ void main() { TweenAnimationBuilder( duration: const Duration(seconds: 1), tween: IntTween(begin: 10, end: 110), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -46,7 +44,7 @@ void main() { TweenAnimationBuilder( duration: const Duration(seconds: 1), tween: IntTween(end: 100), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -70,7 +68,7 @@ void main() { TweenAnimationBuilder( duration: const Duration(seconds: 1), tween: IntTween(begin: 100, end: 100), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -88,11 +86,11 @@ void main() { testWidgets('Replace tween animates new tween', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween}) { + Widget buildWidget({required IntTween tween}) { return TweenAnimationBuilder( duration: const Duration(seconds: 1), tween: tween, - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -116,12 +114,12 @@ void main() { testWidgets('Curve is respected', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween, Curve curve}) { + Widget buildWidget({required IntTween tween, required Curve curve}) { return TweenAnimationBuilder( duration: const Duration(seconds: 1), tween: tween, curve: curve, - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -146,11 +144,11 @@ void main() { testWidgets('Duration is respected', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween, Duration duration}) { + Widget buildWidget({required IntTween tween, required Duration duration}) { return TweenAnimationBuilder( tween: tween, duration: duration, - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -179,8 +177,8 @@ void main() { child: TweenAnimationBuilder( tween: IntTween(begin: 0, end: 100), duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { - return child; + builder: (BuildContext context, int i, Widget? child) { + return child!; }, child: const Text('Hello World'), ), @@ -193,11 +191,11 @@ void main() { group('Change tween gapless while', () { testWidgets('running forward', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween}) { + Widget buildWidget({required IntTween tween}) { return TweenAnimationBuilder( tween: tween, duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -228,11 +226,11 @@ void main() { testWidgets('running forward and then reverse with same tween instance', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween}) { + Widget buildWidget({required IntTween tween}) { return TweenAnimationBuilder( tween: tween, duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -258,11 +256,11 @@ void main() { testWidgets('Changing tween while gapless tween change is in progress', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween}) { + Widget buildWidget({required IntTween tween}) { return TweenAnimationBuilder( tween: tween, duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -298,12 +296,12 @@ void main() { testWidgets('Changing curve while no animation is running does not trigger animation', (WidgetTester tester) async { final List values = []; - Widget buildWidget({Curve curve}) { + Widget buildWidget({required Curve curve}) { return TweenAnimationBuilder( tween: IntTween(begin: 0, end: 100), curve: curve, duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -327,11 +325,11 @@ void main() { testWidgets('Setting same tween and direction does not trigger animation', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween}) { + Widget buildWidget({required IntTween tween}) { return TweenAnimationBuilder( tween: tween, duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, @@ -356,11 +354,11 @@ void main() { testWidgets('Setting same tween and direction while gapless animation is in progress works', (WidgetTester tester) async { final List values = []; - Widget buildWidget({IntTween tween}) { + Widget buildWidget({required IntTween tween}) { return TweenAnimationBuilder( tween: tween, duration: const Duration(seconds: 1), - builder: (BuildContext context, int i, Widget child) { + builder: (BuildContext context, int i, Widget? child) { values.add(i); return const Placeholder(); }, diff --git a/packages/flutter/test/widgets/unique_widget_test.dart b/packages/flutter/test/widgets/unique_widget_test.dart index 20c42cf6f1..b72df13188 100644 --- a/packages/flutter/test/widgets/unique_widget_test.dart +++ b/packages/flutter/test/widgets/unique_widget_test.dart @@ -2,13 +2,11 @@ // 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'; class TestUniqueWidget extends UniqueWidget { - const TestUniqueWidget({ GlobalKey key }) : super(key: key); + const TestUniqueWidget({ required GlobalKey key }) : super(key: key); @override TestUniqueWidgetState createState() => TestUniqueWidgetState(); @@ -25,7 +23,7 @@ void main() { await tester.pumpWidget(widget); - final TestUniqueWidgetState state = widget.currentState; + final TestUniqueWidgetState state = widget.currentState!; expect(state, isNotNull); diff --git a/packages/flutter/test/widgets/value_listenable_builder_test.dart b/packages/flutter/test/widgets/value_listenable_builder_test.dart index a2b472aab7..e90658a57c 100644 --- a/packages/flutter/test/widgets/value_listenable_builder_test.dart +++ b/packages/flutter/test/widgets/value_listenable_builder_test.dart @@ -2,24 +2,22 @@ // 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/foundation.dart'; import 'package:flutter/widgets.dart'; void main() { - SpyStringValueNotifier valueListenable; - Widget textBuilderUnderTest; + late SpyStringValueNotifier valueListenable; + late Widget textBuilderUnderTest; Widget builderForValueListenable( - ValueListenable valueListenable, + ValueListenable valueListenable, ) { return Directionality( textDirection: TextDirection.ltr, - child: ValueListenableBuilder( + child: ValueListenableBuilder( valueListenable: valueListenable, - builder: (BuildContext context, String value, Widget child) { + builder: (BuildContext context, String? value, Widget? child) { if (value == null) return const Placeholder(); return Text(value); @@ -67,7 +65,7 @@ void main() { await tester.pump(); expect(find.text('Gilfoyle'), findsOneWidget); - final ValueListenable differentListenable = + final ValueListenable differentListenable = SpyStringValueNotifier('Hendricks'); await tester.pumpWidget(builderForValueListenable(differentListenable)); @@ -83,7 +81,7 @@ void main() { await tester.pump(); expect(find.text('Gilfoyle'), findsOneWidget); - final ValueListenable differentListenable = + final ValueListenable differentListenable = SpyStringValueNotifier('Hendricks'); await tester.pumpWidget(builderForValueListenable(differentListenable)); @@ -113,8 +111,8 @@ void main() { }); } -class SpyStringValueNotifier extends ValueNotifier { - SpyStringValueNotifier(String initialValue) : super(initialValue); +class SpyStringValueNotifier extends ValueNotifier { + SpyStringValueNotifier(String? initialValue) : super(initialValue); /// Override for test visibility only. @override diff --git a/packages/flutter/test/widgets/visibility_test.dart b/packages/flutter/test/widgets/visibility_test.dart index 3ad71a6a54..cda26e7577 100644 --- a/packages/flutter/test/widgets/visibility_test.dart +++ b/packages/flutter/test/widgets/visibility_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/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -11,7 +9,7 @@ import '../rendering/mock_canvas.dart'; import 'semantics_tester.dart'; 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 List log; @override diff --git a/packages/flutter/test/widgets/widget_inspector_init_with_structured_error_test.dart b/packages/flutter/test/widgets/widget_inspector_init_with_structured_error_test.dart index 41b78e57dd..a2b5d7a101 100644 --- a/packages/flutter/test/widgets/widget_inspector_init_with_structured_error_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_init_with_structured_error_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/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -25,8 +23,8 @@ class StructuredErrorTestService extends TestWidgetInspectorService { static void runTests() { final StructuredErrorTestService service = StructuredErrorTestService(); WidgetInspectorService.instance = service; - FlutterExceptionHandler testHandler; - FlutterExceptionHandler inspectorServiceErrorHandler; + FlutterExceptionHandler? testHandler; + FlutterExceptionHandler? inspectorServiceErrorHandler; setUpAll(() { inspectorServiceErrorHandler = FlutterError.onError; @@ -42,7 +40,7 @@ class StructuredErrorTestService extends TestWidgetInspectorService { // what it was after WidgetInspectorService::initServiceExtensions ran. FlutterError.onError = inspectorServiceErrorHandler; - List> flutterErrorEvents = + List> flutterErrorEvents = service.getEventsDispatched('Flutter.Error'); expect(flutterErrorEvents, hasLength(0)); diff --git a/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart b/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart index 2740746b2d..27b12e3daa 100644 --- a/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_structure_error_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 'dart:async'; import 'dart:convert'; @@ -16,41 +14,41 @@ void main() { StructureErrorTestWidgetInspectorService.runTests(); } -typedef InspectorServiceExtensionCallback = FutureOr> Function(Map parameters); +typedef InspectorServiceExtensionCallback = FutureOr> Function(Map parameters); class StructureErrorTestWidgetInspectorService extends Object with WidgetInspectorService { final Map extensions = {}; - final Map>> eventsDispatched = >>{}; + final Map>> eventsDispatched = >>{}; @override void registerServiceExtension({ - @required String name, - @required FutureOr> callback(Map parameters), + required String name, + required FutureOr> callback(Map parameters), }) { assert(!extensions.containsKey(name)); extensions[name] = callback; } @override - void postEvent(String eventKind, Map eventData) { + void postEvent(String eventKind, Map eventData) { getEventsDispatched(eventKind).add(eventData); } - List> getEventsDispatched(String eventKind) { - return eventsDispatched.putIfAbsent(eventKind, () => >[]); + List> getEventsDispatched(String eventKind) { + return eventsDispatched.putIfAbsent(eventKind, () => >[]); } - Iterable> getServiceExtensionStateChangedEvents(String extensionName) { + Iterable> getServiceExtensionStateChangedEvents(String extensionName) { return getEventsDispatched('Flutter.ServiceExtensionStateChanged') - .where((Map event) => event['extension'] == extensionName); + .where((Map event) => event['extension'] == extensionName); } Future testBoolExtension(String name, Map arguments) async { expect(extensions, contains(name)); // Encode and decode to JSON to match behavior using a real service // 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 WidgetInspectorService.instance = service; 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 // initializes. FlutterError.onError = (FlutterErrorDetails details) { @@ -90,4 +88,4 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect } }); } -} \ No newline at end of file +} diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index 42e2356f82..4e4546e104 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_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 'dart:async'; import 'dart:convert'; import 'dart:math'; @@ -22,7 +20,7 @@ import 'widget_inspector_test_utils.dart'; // columns will impact whether tests pass. class ClockDemo extends StatefulWidget { - const ClockDemo({ Key key }) : super(key: key); + const ClockDemo({ Key? key }) : super(key: key); @override _ClockDemoState createState() => _ClockDemoState(); } @@ -60,7 +58,7 @@ class _ClockDemoState extends State { class ClockText extends StatefulWidget { const ClockText({ - Key key, + Key? key, this.utcOffset = 0, }) : super(key: key); @@ -71,7 +69,7 @@ class ClockText extends StatefulWidget { } class _ClockTextState extends State { - DateTime currentTime = DateTime.now(); + DateTime? currentTime = DateTime.now(); void updateTime() { setState(() { @@ -91,7 +89,7 @@ class _ClockTextState extends State { return const Text('stopped'); } return Text( - currentTime + currentTime! .toUtc() .add(Duration(hours: widget.utcOffset)) .toIso8601String(), @@ -110,7 +108,7 @@ class CyclicDiagnostic extends DiagnosticableTree { CyclicDiagnostic(this.name); // Field used to create cyclic relationships. - CyclicDiagnostic related; + CyclicDiagnostic? related; final List children = []; final String name; @@ -137,10 +135,10 @@ class CyclicDiagnostic extends DiagnosticableTree { class _CreationLocation { const _CreationLocation({ - @required this.file, - @required this.line, - @required this.column, - @required this.id, + required this.file, + required this.line, + required this.column, + required this.id, }); final String file; @@ -205,8 +203,8 @@ class RenderRepaintBoundaryWithDebugPaint extends RenderRepaintBoundary { class RepaintBoundaryWithDebugPaint extends RepaintBoundary { /// Creates a widget that isolates repaints. const RepaintBoundaryWithDebugPaint({ - Key key, - Widget child, + Key? key, + Widget? child, }) : super(key: key, child: child); @override @@ -216,7 +214,7 @@ class RepaintBoundaryWithDebugPaint extends RepaintBoundary { } int getChildLayerCount(OffsetLayer layer) { - Layer child = layer.firstChild; + Layer? child = layer.firstChild; int count = 0; while (child != null) { count++; @@ -282,7 +280,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { dynamic getInspectorState() => inspectorKey.currentState; String paragraphText(RenderParagraph paragraph) { final TextSpan textSpan = paragraph.text as TextSpan; - return textSpan.text; + return textSpan.text!; } await tester.pumpWidget( @@ -320,8 +318,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Tap intercepted by the inspector expect(log, equals([])); final InspectorSelection selection = getInspectorState().selection as InspectorSelection; - expect(paragraphText(selection.current as RenderParagraph), equals('TOP')); - final RenderObject topButton = find.byKey(topButtonKey).evaluate().first.renderObject; + expect(paragraphText(selection.current! as RenderParagraph), equals('TOP')); + final RenderObject topButton = find.byKey(topButtonKey).evaluate().first.renderObject!; expect(selection.candidates, contains(topButton)); await tester.tap(find.text('TOP')); @@ -457,7 +455,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final GlobalKey inspectorKey = GlobalKey(); final GlobalKey clickTarget = GlobalKey(); - Widget createSubtree({ double width, Key key }) { + Widget createSubtree({ double? width, Key? key }) { return Stack( children: [ Positioned( @@ -583,7 +581,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { dynamic getInspectorState() => inspector1Key.currentState; String paragraphText(RenderParagraph paragraph) { final TextSpan textSpan = paragraph.text as TextSpan; - return textSpan.text; + return textSpan.text!; } await tester.pumpWidget( @@ -618,15 +616,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final InspectorSelection selection = getInspectorState().selection as InspectorSelection; // The selection is static, so it may be initialized from previous tests. - selection?.clear(); + selection.clear(); await tester.tap(find.text('Child 1')); await tester.pump(); - expect(paragraphText(selection.current as RenderParagraph), equals('Child 1')); + expect(paragraphText(selection.current! as RenderParagraph), equals('Child 1')); await tester.tap(find.text('Child 2')); await tester.pump(); - expect(paragraphText(selection.current as RenderParagraph), equals('Child 2')); + expect(paragraphText(selection.current! as RenderParagraph), equals('Child 2')); }); test('WidgetInspectorService null id', () { @@ -641,7 +639,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { const String group1 = 'group-1'; const String group2 = 'group-2'; const String group3 = 'group-3'; - final String aId = service.toId(a, group1); + final String? aId = service.toId(a, group1); expect(service.toId(a, group2), equals(aId)); expect(service.toId(a, group3), equals(aId)); service.disposeGroup(group1); @@ -657,8 +655,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Object b = Object(); const String group1 = 'group-1'; const String group2 = 'group-2'; - final String aId = service.toId(a, group1); - final String bId = service.toId(b, group1); + final String? aId = service.toId(a, group1); + final String? bId = service.toId(b, group1); expect(service.toId(a, group2), equals(aId)); service.disposeId(bId, group1); expect(() => service.toObject(bId), throwsFlutterError); @@ -672,10 +670,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { const String group = 'test-group'; const Text widget = Text('a', textDirection: TextDirection.ltr); service.disposeAllGroups(); - final String id = service.toId(widget, group); + final String id = service.toId(widget, group)!; expect(service.toObjectForSourceLocation(id), equals(widget)); final Element element = widget.createElement(); - final String elementId = service.toId(element, group); + final String elementId = service.toId(element, group)!; expect(service.toObjectForSourceLocation(elementId), equals(widget)); expect(element, isNot(equals(widget))); service.disposeGroup(group); @@ -693,10 +691,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { const String group3 = 'group-3'; service.disposeAllGroups(); - final String aId = service.toId(a, group1); - final String bId = service.toId(b, group2); - final String cId = service.toId(c, group3); - final String dId = service.toId(d, group1); + final String? aId = service.toId(a, group1); + final String? bId = service.toId(b, group2); + final String? cId = service.toId(c, group3); + final String? dId = service.toId(d, group1); // Make sure we get a consistent id if we add the object to a group multiple // times. expect(aId, equals(service.toId(a, group1))); @@ -745,7 +743,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementB.renderObject); expect(selectionChangedCount, equals(2)); expect(service.selection.current, equals(elementB.renderObject)); - expect(service.selection.currentElement, equals((elementB.renderObject.debugCreator as DebugCreator).element)); + expect(service.selection.currentElement, equals((elementB.renderObject!.debugCreator! as DebugCreator).element)); service.setSelection('invalid selection'); expect(selectionChangedCount, equals(2)); @@ -779,11 +777,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); final Element elementB = find.text('b').evaluate().first; - final String bId = service.toId(elementB, group); - final Object jsonList = json.decode(service.getParentChain(bId, group)); + final String bId = service.toId(elementB, group)!; + final Object? jsonList = json.decode(service.getParentChain(bId, group)); expect(jsonList, isList); - final List chainElements = jsonList as List; - final List expectedChain = elementB.debugGetDiagnosticChain()?.reversed?.toList(); + final List chainElements = jsonList! as List; + final List expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); // Sanity check that the chain goes back to the root. expect(expectedChain.first, tester.binding.renderViewElement); @@ -793,12 +791,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Map chainNode = chainElements[i] as Map; final Element element = expectedChain[i]; expect(chainNode['node'], isMap); - final Map jsonNode = chainNode['node'] as Map; - expect(service.toObject(jsonNode['valueId'] as String), equals(element)); - expect(service.toObject(jsonNode['objectId'] as String), isA()); + final Map jsonNode = chainNode['node']! as Map; + expect(service.toObject(jsonNode['valueId']! as String), equals(element)); + expect(service.toObject(jsonNode['objectId']! as String), isA()); expect(chainNode['children'], isList); - final List jsonChildren = chainNode['children'] as List; + final List jsonChildren = chainNode['children']! as List; final List childrenElements = []; element.visitChildren(childrenElements.add); expect(jsonChildren.length, equals(childrenElements.length)); @@ -810,8 +808,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { for (int j = 0; j < childrenElements.length; j += 1) { expect(jsonChildren[j], isMap); final Map childJson = jsonChildren[j] as Map; - expect(service.toObject(childJson['valueId'] as String), equals(childrenElements[j])); - expect(service.toObject(childJson['objectId'] as String), isA()); + expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); + expect(service.toObject(childJson['objectId']! as String), isA()); } } }); @@ -820,15 +818,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); const String group = 'group'; service.disposeAllGroups(); - final String id = service.toId(diagnostic, group); + final String id = service.toId(diagnostic, group)!; final List propertiesJson = json.decode(service.getProperties(id, group)) as List; final List properties = diagnostic.getProperties(); expect(properties, isNotEmpty); expect(propertiesJson.length, equals(properties.length)); for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i] as Map; - expect(service.toObject(propertyJson['valueId'] as String), equals(properties[i].value)); - expect(service.toObject(propertyJson['objectId'] as String), isA()); + expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); + expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -849,15 +847,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); service.disposeAllGroups(); - final String id = service.toId(diagnostic, group); + final String id = service.toId(diagnostic, group)!; final List propertiesJson = json.decode(service.getChildren(id, group)) as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(propertiesJson.length, equals(children.length)); for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i] as Map; - expect(service.toObject(propertyJson['valueId'] as String), equals(children[i].value)); - expect(service.toObject(propertyJson['objectId'] as String), isA()); + expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); + expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -881,21 +879,21 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setPubRootDirectories([]); service.setSelection(elementA, 'my-group'); final Map jsonA = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocationA = jsonA['creationLocation'] as Map; + final Map creationLocationA = jsonA['creationLocation']! as Map; expect(creationLocationA, isNotNull); - final String fileA = creationLocationA['file'] as String; - final int lineA = creationLocationA['line'] as int; - final int columnA = creationLocationA['column'] as int; - final List parameterLocationsA = creationLocationA['parameterLocations'] as List; + final String fileA = creationLocationA['file']! as String; + final int lineA = creationLocationA['line']! as int; + final int columnA = creationLocationA['column']! as int; + final List parameterLocationsA = creationLocationA['parameterLocations']! as List; service.setSelection(elementB, 'my-group'); final Map jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocationB = jsonB['creationLocation'] as Map; + final Map creationLocationB = jsonB['creationLocation']! as Map; expect(creationLocationB, isNotNull); - final String fileB = creationLocationB['file'] as String; - final int lineB = creationLocationB['line'] as int; - final int columnB = creationLocationB['column'] as int; - final List parameterLocationsB = creationLocationB['parameterLocations'] as List; + final String fileB = creationLocationB['file']! as String; + final int lineB = creationLocationB['line']! as int; + final int columnB = creationLocationB['column']! as int; + final List parameterLocationsB = creationLocationB['parameterLocations']! as List; expect(fileA, endsWith('widget_inspector_test.dart')); expect(fileA, equals(fileB)); // We don't hardcode the actual lines the widgets are created on as that @@ -936,13 +934,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); final Element elementA = find.text('a').evaluate().first; - String pubRootTest; + late String pubRootTest; if (widgetTracked) { final Map jsonObject = json.decode( service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocation = jsonObject['creationLocation'] as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String fileA = creationLocation['file'] as String; + final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); expect(jsonObject, isNot(contains('createdByLocalProject'))); final List segments = Uri @@ -998,13 +996,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); final Element elementA = find.text('a').evaluate().first; - String pubRootTest; + late String pubRootTest; if (widgetTracked) { final Map jsonObject = json.decode( service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocation = jsonObject['creationLocation'] as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String fileA = creationLocation['file'] as String; + final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); expect(jsonObject, isNot(contains('createdByLocalProject'))); final List segments = Uri @@ -1064,9 +1062,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setPubRootDirectories([]); service.setSelection(elementA, 'my-group'); Map jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; - Map creationLocation = jsonObject['creationLocation'] as Map; + Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String fileA = creationLocation['file'] as String; + final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); expect(jsonObject, isNot(contains('createdByLocalProject'))); final List segments = Uri.parse(fileA).pathSegments; @@ -1103,11 +1101,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setPubRootDirectories([pubRootTest]); jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; expect(jsonObject, isNot(contains('createdByLocalProject'))); - creationLocation = jsonObject['creationLocation'] as Map; + creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); // This RichText widget is created by the build method of the Text widget // thus the creation location is in text.dart not basic.dart - final List pathSegmentsFramework = Uri.parse(creationLocation['file'] as String).pathSegments; + final List pathSegmentsFramework = Uri.parse(creationLocation['file']! as String).pathSegments; expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart')); // Strip off /src/widgets/text.dart. @@ -1129,7 +1127,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { const String group1 = 'group-1'; const String group2 = 'group-2'; const String group3 = 'group-3'; - final String aId = service.toId(a, group1); + final String? aId = service.toId(a, group1); expect(service.toId(a, group2), equals(aId)); expect(service.toId(a, group3), equals(aId)); await service.testExtension('disposeGroup', {'objectGroup': group1}); @@ -1144,8 +1142,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Object b = Object(); const String group1 = 'group-1'; const String group2 = 'group-2'; - final String aId = service.toId(a, group1); - final String bId = service.toId(b, group1); + final String aId = service.toId(a, group1)!; + final String bId = service.toId(b, group1)!; expect(service.toId(a, group2), equals(aId)); await service.testExtension('disposeId', {'arg': bId, 'objectGroup': group1}); expect(() => service.toObject(bId), throwsFlutterError); @@ -1186,13 +1184,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementB.renderObject); expect(selectionChangedCount, equals(2)); expect(service.selection.current, equals(elementB.renderObject)); - expect(service.selection.currentElement, equals((elementB.renderObject.debugCreator as DebugCreator).element)); + expect(service.selection.currentElement, equals((elementB.renderObject!.debugCreator! as DebugCreator).element)); service.setSelection('invalid selection'); expect(selectionChangedCount, equals(2)); expect(service.selection.current, equals(elementB.renderObject)); - await service.testExtension('setSelectionById', {'arg': service.toId(elementA, 'my-group'), 'objectGroup': 'my-group'}); + await service.testExtension('setSelectionById', {'arg': service.toId(elementA, 'my-group')!, 'objectGroup': 'my-group'}); expect(selectionChangedCount, equals(3)); expect(service.selection.currentElement, equals(elementA)); expect(service.selection.current, equals(elementA.renderObject)); @@ -1219,11 +1217,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); final Element elementB = find.text('b').evaluate().first; - final String bId = service.toId(elementB, group); - final Object jsonList = await service.testExtension('getParentChain', {'arg': bId, 'objectGroup': group}); + final String bId = service.toId(elementB, group)!; + final Object? jsonList = await service.testExtension('getParentChain', {'arg': bId, 'objectGroup': group}); expect(jsonList, isList); - final List chainElements = jsonList as List; - final List expectedChain = elementB.debugGetDiagnosticChain()?.reversed?.toList(); + final List chainElements = jsonList! as List; + final List expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); // Sanity check that the chain goes back to the root. expect(expectedChain.first, tester.binding.renderViewElement); @@ -1233,12 +1231,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Map chainNode = chainElements[i] as Map; final Element element = expectedChain[i]; expect(chainNode['node'], isMap); - final Map jsonNode = chainNode['node'] as Map; - expect(service.toObject(jsonNode['valueId'] as String), equals(element)); - expect(service.toObject(jsonNode['objectId'] as String), isA()); + final Map jsonNode = chainNode['node']! as Map; + expect(service.toObject(jsonNode['valueId']! as String), equals(element)); + expect(service.toObject(jsonNode['objectId']! as String), isA()); expect(chainNode['children'], isList); - final List jsonChildren = chainNode['children'] as List; + final List jsonChildren = chainNode['children']! as List; final List childrenElements = []; element.visitChildren(childrenElements.add); expect(jsonChildren.length, equals(childrenElements.length)); @@ -1250,8 +1248,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { for (int j = 0; j < childrenElements.length; j += 1) { expect(jsonChildren[j], isMap); final Map childJson = jsonChildren[j] as Map; - expect(service.toObject(childJson['valueId'] as String), equals(childrenElements[j])); - expect(service.toObject(childJson['objectId'] as String), isA()); + expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); + expect(service.toObject(childJson['objectId']! as String), isA()); } } }); @@ -1259,15 +1257,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { test('ext.flutter.inspector.getProperties', () async { final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); const String group = 'group'; - final String id = service.toId(diagnostic, group); - final List propertiesJson = await service.testExtension('getProperties', {'arg': id, 'objectGroup': group}) as List; + final String id = service.toId(diagnostic, group)!; + final List propertiesJson = (await service.testExtension('getProperties', {'arg': id, 'objectGroup': group}))! as List; final List properties = diagnostic.getProperties(); expect(properties, isNotEmpty); expect(propertiesJson.length, equals(properties.length)); for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i] as Map; - expect(service.toObject(propertyJson['valueId'] as String), equals(properties[i].value)); - expect(service.toObject(propertyJson['objectId'] as String), isA()); + expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); + expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -1287,15 +1285,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group); - final List propertiesJson = await service.testExtension('getChildren', {'arg': id, 'objectGroup': group}) as List; + final String id = service.toId(diagnostic, group)!; + final List propertiesJson = (await service.testExtension('getChildren', {'arg': id, 'objectGroup': group}))! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(propertiesJson.length, equals(children.length)); for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i] as Map; - expect(service.toObject(propertyJson['valueId'] as String), equals(children[i].value)); - expect(service.toObject(propertyJson['objectId'] as String), isA()); + expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); + expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -1315,20 +1313,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group); - final List childrenJson = await service.testExtension('getChildrenDetailsSubtree', {'arg': id, 'objectGroup': group}) as List; + final String id = service.toId(diagnostic, group)!; + final List childrenJson = (await service.testExtension('getChildrenDetailsSubtree', {'arg': id, 'objectGroup': group}))! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); for (int i = 0; i < childrenJson.length; ++i) { final Map childJson = childrenJson[i] as Map; - expect(service.toObject(childJson['valueId'] as String), equals(children[i].value)); - expect(service.toObject(childJson['objectId'] as String), isA()); - final List propertiesJson = childJson['properties'] as List; - final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId'] as String) as DiagnosticsNode; + expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); + expect(service.toObject(childJson['objectId']! as String), isA()); + final List propertiesJson = childJson['properties']! as List; + final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode; final List expectedProperties = diagnosticsNode.getProperties(); for (final Map propertyJson in propertiesJson.cast>()) { - final Object property = service.toObject(propertyJson['objectId'] as String); + final Object? property = service.toObject(propertyJson['objectId']! as String); expect(property, isA()); expect(expectedProperties, contains(property)); } @@ -1351,37 +1349,37 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group); - final Map subtreeJson = await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}) as Map; + final String id = service.toId(diagnostic, group)!; + final Map subtreeJson = (await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}))! as Map; expect(subtreeJson['objectId'], equals(id)); - final List childrenJson = subtreeJson['children'] as List; + final List childrenJson = subtreeJson['children']! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); for (int i = 0; i < childrenJson.length; ++i) { final Map childJson = childrenJson[i] as Map; - expect(service.toObject(childJson['valueId'] as String), equals(children[i].value)); - expect(service.toObject(childJson['objectId'] as String), isA()); - final List propertiesJson = childJson['properties'] as List; + expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); + expect(service.toObject(childJson['objectId']! as String), isA()); + final List propertiesJson = childJson['properties']! as List; for (final Map propertyJson in propertiesJson.cast>()) { expect(propertyJson, isNot(contains('children'))); } - final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId'] as String) as DiagnosticsNode; + final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode; final List expectedProperties = diagnosticsNode.getProperties(); for (final Map propertyJson in propertiesJson.cast>()) { - final Object property = service.toObject(propertyJson['objectId'] as String); + final Object property = service.toObject(propertyJson['objectId']! as String)!; expect(property, isA()); expect(expectedProperties, contains(property)); } } - final Map deepSubtreeJson = await service.testExtension( + final Map deepSubtreeJson = (await service.testExtension( 'getDetailsSubtree', {'arg': id, 'objectGroup': group, 'subtreeDepth': '3'}, - ) as Map; - final List deepChildrenJson = deepSubtreeJson['children'] as List; + ))! as Map; + final List deepChildrenJson = deepSubtreeJson['children']! as List; for (final Map childJson in deepChildrenJson.cast>()) { - final List propertiesJson = childJson['properties'] as List; + final List propertiesJson = childJson['properties']! as List; for (final Map propertyJson in propertiesJson.cast>()) { expect(propertyJson, contains('children')); } @@ -1397,11 +1395,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { b.related = a; final DiagnosticsNode diagnostic = a.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group); - final Map subtreeJson = await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}) as Map; + final String id = service.toId(diagnostic, group)!; + final Map subtreeJson = (await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}))! as Map; expect(subtreeJson['objectId'], equals(id)); expect(subtreeJson, contains('children')); - final List propertiesJson = subtreeJson['properties'] as List; + final List propertiesJson = subtreeJson['properties']! as List; expect(propertiesJson.length, equals(1)); final Map relatedProperty = propertiesJson.first as Map; expect(relatedProperty['name'], equals('related')); @@ -1409,7 +1407,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(relatedProperty, contains('isDiagnosticableValue')); expect(relatedProperty, isNot(contains('children'))); expect(relatedProperty, contains('properties')); - final List relatedWidgetProperties = relatedProperty['properties'] as List; + final List relatedWidgetProperties = relatedProperty['properties']! as List; expect(relatedWidgetProperties.length, equals(1)); final Map nestedRelatedProperty = relatedWidgetProperties.first as Map; expect(nestedRelatedProperty['name'], equals('related')); @@ -1442,22 +1440,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - final Map jsonA = await service.testExtension('getSelectedWidget', {'arg': null, 'objectGroup': 'my-group'}) as Map; + final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; await service.testExtension('setPubRootDirectories', {}); - Map rootJson = await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}) as Map; + Map rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; // We haven't yet properly specified which directories are summary tree // directories so we get an empty tree other than the root that is always // included. - final Object rootWidget = service.toObject(rootJson['valueId'] as String); + final Object? rootWidget = service.toObject(rootJson['valueId']! as String); expect(rootWidget, equals(WidgetsBinding.instance?.renderViewElement)); - List childrenJson = rootJson['children'] as List; + List childrenJson = rootJson['children']! as List; // There are no summary tree children. expect(childrenJson.length, equals(0)); - final Map creationLocation = jsonA['creationLocation'] as Map; + final Map creationLocation = jsonA['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String testFile = creationLocation['file'] as String; + final String testFile = creationLocation['file']! as String; expect(testFile, endsWith('widget_inspector_test.dart')); final List segments = Uri.parse(testFile).pathSegments; // Strip a couple subdirectories away to generate a plausible pub root @@ -1465,14 +1463,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String pubRootTest = '/' + segments.take(segments.length - 2).join('/'); await service.testExtension('setPubRootDirectories', {'arg0': pubRootTest}); - rootJson = await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}) as Map; - childrenJson = rootJson['children'] as List; + rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; + childrenJson = rootJson['children']! as List; // The tree of nodes returned contains all widgets created directly by the // test. - childrenJson = rootJson['children'] as List; + childrenJson = rootJson['children']! as List; expect(childrenJson.length, equals(1)); - List alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', {'arg': rootJson['objectId'] as String, 'objectGroup': group}) as List; + List alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': rootJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length, equals(1)); Map childJson = childrenJson[0] as Map; Map alternateChildJson = alternateChildrenJson[0] as Map; @@ -1480,8 +1478,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(alternateChildJson['description'], startsWith('Directionality')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - childrenJson = childJson['children'] as List; - alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId'] as String, 'objectGroup': group}) as List; + childrenJson = childJson['children']! as List; + alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length, equals(1)); expect(childrenJson.length, equals(1)); alternateChildJson = alternateChildrenJson[0] as Map; @@ -1489,10 +1487,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(childJson['description'], startsWith('Stack')); expect(alternateChildJson['description'], startsWith('Stack')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - childrenJson = childJson['children'] as List; + childrenJson = childJson['children']! as List; - childrenJson = childJson['children'] as List; - alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId'] as String, 'objectGroup': group}) as List; + childrenJson = childJson['children']! as List; + alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length, equals(3)); expect(childrenJson.length, equals(3)); alternateChildJson = alternateChildrenJson[2] as Map; @@ -1500,7 +1498,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(childJson['description'], startsWith('Text')); expect(alternateChildJson['description'], startsWith('Text')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId'] as String, 'objectGroup': group}) as List; + alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length , equals(0)); expect(childJson['chidlren'], isNull); }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. @@ -1529,18 +1527,18 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - final Map jsonA = await service.testExtension('getSelectedWidget', {'arg': null, 'objectGroup': 'my-group'}) as Map; + final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; service.setSelection(richTextDiagnostic.value, 'my-group'); await service.testExtension('setPubRootDirectories', {}); - Map summarySelection = await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}) as Map; + Map? summarySelection = await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}) as Map?; // No summary selection because we haven't set the pub root directories // yet to indicate what directories are in the summary tree. expect(summarySelection, isNull); - final Map creationLocation = jsonA['creationLocation'] as Map; + final Map creationLocation = jsonA['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String testFile = creationLocation['file'] as String; + final String testFile = creationLocation['file']! as String; expect(testFile, endsWith('widget_inspector_test.dart')); final List segments = Uri.parse(testFile).pathSegments; // Strip a couple subdirectories away to generate a plausible pub root @@ -1548,16 +1546,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String pubRootTest = '/' + segments.take(segments.length - 2).join('/'); await service.testExtension('setPubRootDirectories', {'arg0': pubRootTest}); - summarySelection = await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}) as Map; + summarySelection = (await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}))! as Map; expect(summarySelection['valueId'], isNotNull); // We got the Text element instead of the selected RichText element // because only the RichText element is part of the summary tree. - expect(service.toObject(summarySelection['valueId'] as String), elementA); + expect(service.toObject(summarySelection['valueId']! as String), elementA); // Verify tha the regular getSelectedWidget method still returns // the RichText object not the Text element. - final Map regularSelection = await service.testExtension('getSelectedWidget', {'arg': null, 'objectGroup': 'my-group'}) as Map; - expect(service.toObject(regularSelection['valueId'] as String), richTextDiagnostic.value); + final Map regularSelection = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + expect(service.toObject(regularSelection['valueId']! as String), richTextDiagnostic.value); }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. testWidgets('ext.flutter.inspector creationLocation', (WidgetTester tester) async { @@ -1579,22 +1577,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - final Map jsonA = await service.testExtension('getSelectedWidget', {'arg': null, 'objectGroup': 'my-group'}) as Map; - final Map creationLocationA = jsonA['creationLocation'] as Map; + final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map creationLocationA = jsonA['creationLocation']! as Map; expect(creationLocationA, isNotNull); - final String fileA = creationLocationA['file'] as String; - final int lineA = creationLocationA['line'] as int; - final int columnA = creationLocationA['column'] as int; - final List parameterLocationsA = creationLocationA['parameterLocations'] as List; + final String fileA = creationLocationA['file']! as String; + final int lineA = creationLocationA['line']! as int; + final int columnA = creationLocationA['column']! as int; + final List parameterLocationsA = creationLocationA['parameterLocations']! as List; service.setSelection(elementB, 'my-group'); - final Map jsonB = await service.testExtension('getSelectedWidget', {'arg': null, 'objectGroup': 'my-group'}) as Map; - final Map creationLocationB = jsonB['creationLocation'] as Map; + final Map jsonB = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map creationLocationB = jsonB['creationLocation']! as Map; expect(creationLocationB, isNotNull); - final String fileB = creationLocationB['file'] as String; - final int lineB = creationLocationB['line'] as int; - final int columnB = creationLocationB['column'] as int; - final List parameterLocationsB = creationLocationB['parameterLocations'] as List; + final String fileB = creationLocationB['file']! as String; + final int lineB = creationLocationB['line']! as int; + final int columnB = creationLocationB['column']! as int; + final List parameterLocationsB = creationLocationB['parameterLocations']! as List; expect(fileA, endsWith('widget_inspector_test.dart')); expect(fileA, equals(fileB)); // We don't hardcode the actual lines the widgets are created on as that @@ -1637,10 +1635,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - Map jsonObject = await service.testExtension('getSelectedWidget', {'arg': null, 'objectGroup': 'my-group'}) as Map; - Map creationLocation = jsonObject['creationLocation'] as Map; + Map jsonObject = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String fileA = creationLocation['file'] as String; + final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); expect(jsonObject, isNot(contains('createdByLocalProject'))); final List segments = Uri.parse(fileA).pathSegments; @@ -1678,11 +1676,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setPubRootDirectories([pubRootTest]); jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; expect(jsonObject, isNot(contains('createdByLocalProject'))); - creationLocation = jsonObject['creationLocation'] as Map; + creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); // This RichText widget is created by the build method of the Text widget // thus the creation location is in text.dart not basic.dart - final List pathSegmentsFramework = Uri.parse(creationLocation['file'] as String).pathSegments; + final List pathSegmentsFramework = Uri.parse(creationLocation['file']! as String).pathSegments; expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart')); // Strip off /src/widgets/text.dart. @@ -1707,13 +1705,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; service.setSelection(clockDemoElement, 'my-group'); - final Map jsonObject = await service.testExtension( + final Map jsonObject = (await service.testExtension( 'getSelectedWidget', - {'arg': null, 'objectGroup': 'my-group'}, - ) as Map; - final Map creationLocation = jsonObject['creationLocation'] as Map; + {'objectGroup': 'my-group'}, + ))! as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String file = creationLocation['file'] as String; + final String file = creationLocation['file']! as String; expect(file, endsWith('widget_inspector_test.dart')); final List segments = Uri.parse(file).pathSegments; // Strip a couple subdirectories away to generate a plausible pub root @@ -1723,7 +1721,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await service.testExtension( 'setPubRootDirectories', {'arg0': pubRootTest}); - final List> rebuildEvents = + final List> rebuildEvents = service.getEventsDispatched('Flutter.RebuiltWidgets'); expect(rebuildEvents, isEmpty); @@ -1736,16 +1734,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await tester.pump(); expect(rebuildEvents.length, equals(1)); - Map event = rebuildEvents.removeLast(); + Map event = rebuildEvents.removeLast(); expect(event['startTime'], isA()); - List data = event['events'] as List; + List data = event['events']! as List; expect(data.length, equals(14)); final int numDataEntries = data.length ~/ 2; - Map> newLocations = event['newLocations'] as Map>; + Map> newLocations = event['newLocations']! as Map>; expect(newLocations, isNotNull); expect(newLocations.length, equals(1)); expect(newLocations.keys.first, equals(file)); - final List locationsForFile = newLocations[file]; + final List locationsForFile = newLocations[file]!; expect(locationsForFile.length, equals(21)); final int numLocationEntries = locationsForFile.length ~/ 3; expect(numLocationEntries, equals(numDataEntries)); @@ -1779,7 +1777,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(rebuildEvents.length, equals(1)); event = rebuildEvents.removeLast(); expect(event['startTime'], isA()); - data = event['events'] as List; + data = event['events']! as List; // No new locations were rebuilt. expect(event, isNot(contains('newLocations'))); @@ -1788,19 +1786,19 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(data.length, equals(4)); int id = data[0]; int count = data[1]; - _CreationLocation location = knownLocations[id]; + _CreationLocation location = knownLocations[id]!; expect(location.file, equals(file)); // ClockText widget. - expect(location.line, equals(55)); + expect(location.line, equals(53)); expect(location.column, equals(9)); expect(count, equals(1)); id = data[2]; count = data[3]; - location = knownLocations[id]; + location = knownLocations[id]!; expect(location.file, equals(file)); // Text widget in _ClockTextState build method. - expect(location.line, equals(93)); + expect(location.line, equals(91)); expect(location.column, equals(12)); expect(count, equals(1)); @@ -1815,26 +1813,26 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(rebuildEvents.length, equals(1)); event = rebuildEvents.removeLast(); expect(event['startTime'], isA()); - data = event['events'] as List; + data = event['events']! as List; // No new locations were rebuilt. expect(event, isNot(contains('newLocations'))); expect(data.length, equals(4)); id = data[0]; count = data[1]; - location = knownLocations[id]; + location = knownLocations[id]!; expect(location.file, equals(file)); // ClockText widget. - expect(location.line, equals(55)); + expect(location.line, equals(53)); expect(location.column, equals(9)); expect(count, equals(3)); // 3 clock widget instances rebuilt. id = data[2]; count = data[3]; - location = knownLocations[id]; + location = knownLocations[id]!; expect(location.file, equals(file)); // Text widget in _ClockTextState build method. - expect(location.line, equals(93)); + expect(location.line, equals(91)); expect(location.column, equals(12)); expect(count, equals(3)); // 3 clock widget instances rebuilt. @@ -1849,7 +1847,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(rebuildEvents.length, equals(1)); event = rebuildEvents.removeLast(); expect(event['startTime'], isA()); - data = event['events'] as List; + data = event['events']! as List; // No new locations were rebuilt. expect(event, isNot(contains('newLocations'))); @@ -1866,8 +1864,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(rebuildEvents.length, equals(1)); event = rebuildEvents.removeLast(); expect(event['startTime'], isA()); - data = event['events'] as List; - newLocations = event['newLocations'] as Map>; + data = event['events']! as List; + newLocations = event['newLocations']! as Map>; expect(data.length, equals(4)); // The second pair in data is the previously unseen rebuild location. @@ -1903,13 +1901,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; service.setSelection(clockDemoElement, 'my-group'); - final Map jsonObject = await service.testExtension( + final Map jsonObject = (await service.testExtension( 'getSelectedWidget', - {'arg': null, 'objectGroup': 'my-group'}) as Map; + {'objectGroup': 'my-group'}))! as Map; final Map creationLocation = - jsonObject['creationLocation'] as Map; + jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String file = creationLocation['file'] as String; + final String file = creationLocation['file']! as String; expect(file, endsWith('widget_inspector_test.dart')); final List segments = Uri.parse(file).pathSegments; // Strip a couple subdirectories away to generate a plausible pub root @@ -1919,7 +1917,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await service.testExtension( 'setPubRootDirectories', {'arg0': pubRootTest}); - final List> repaintEvents = + final List> repaintEvents = service.getEventsDispatched('Flutter.RepaintWidgets'); expect(repaintEvents, isEmpty); @@ -1935,16 +1933,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await tester.pump(); expect(repaintEvents.length, equals(1)); - Map event = repaintEvents.removeLast(); + Map event = repaintEvents.removeLast(); expect(event['startTime'], isA()); - List data = event['events'] as List; + List data = event['events']! as List; expect(data.length, equals(18)); final int numDataEntries = data.length ~/ 2; - final Map> newLocations = event['newLocations'] as Map>; + final Map> newLocations = event['newLocations']! as Map>; expect(newLocations, isNotNull); expect(newLocations.length, equals(1)); expect(newLocations.keys.first, equals(file)); - final List locationsForFile = newLocations[file]; + final List locationsForFile = newLocations[file]!; expect(locationsForFile.length, equals(27)); final int numLocationEntries = locationsForFile.length ~/ 3; expect(numLocationEntries, equals(numDataEntries)); @@ -1979,7 +1977,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(repaintEvents.length, equals(1)); event = repaintEvents.removeLast(); expect(event['startTime'], isA()); - data = event['events'] as List; + data = event['events']! as List; // No new locations were rebuilt. expect(event, isNot(contains('newLocations'))); @@ -2003,8 +2001,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. testWidgets('ext.flutter.inspector.show', (WidgetTester tester) async { - final Iterable> extensionChangedEvents = service.getServiceExtensionStateChangedEvents('ext.flutter.inspector.show'); - Map extensionChangedEvent; + final Iterable> extensionChangedEvents = service.getServiceExtensionStateChangedEvents('ext.flutter.inspector.show'); + Map extensionChangedEvent; service.rebuildCount = 0; expect(extensionChangedEvents, isEmpty); @@ -2095,9 +2093,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element repaintBoundary = find.byType(RepaintBoundaryWithDebugPaint).evaluate().single; - final RenderRepaintBoundary renderObject = repaintBoundary.renderObject as RenderRepaintBoundary; + final RenderRepaintBoundary renderObject = repaintBoundary.renderObject! as RenderRepaintBoundary; - final OffsetLayer layer = renderObject.debugLayer as OffsetLayer; + final OffsetLayer layer = renderObject.debugLayer! as OffsetLayer; final int expectedChildLayerCount = getChildLayerCount(layer); expect(expectedChildLayerCount, equals(2)); await expectLater( @@ -2123,8 +2121,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { matchesGoldenFile('inspector.repaint_boundary_margin_large.png'), ); - final Layer layerParent = layer.parent; - final Layer firstChild = layer.firstChild; + final Layer? layerParent = layer.parent; + final Layer? firstChild = layer.firstChild; expect(layerParent, isNotNull); expect(firstChild, isNotNull); @@ -2212,7 +2210,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Verify calling the screenshot method still works if the RenderObject // needs to be laid out again. final RenderObject container = - find.byKey(outerContainerKey).evaluate().single.renderObject; + find.byKey(outerContainerKey).evaluate().single.renderObject!; container ..markNeedsLayout() ..markNeedsPaint(); @@ -2264,7 +2262,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element clipRect = find.byType(ClipRRect).evaluate().single; - final Future clipRectScreenshot = service.screenshot( + final Future clipRectScreenshot = service.screenshot( clipRect, width: 100.0, height: 100.0, @@ -2280,10 +2278,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Verify we get the same image if we go through the service extension // instead of invoking the screenshot method directly. - final Future base64ScreenshotFuture = service.testExtension( + final Future base64ScreenshotFuture = service.testExtension( 'screenshot', { - 'id': service.toId(clipRect, 'group'), + 'id': service.toId(clipRect, 'group')!, 'width': '100.0', 'height': '100.0', 'margin': '20.0', @@ -2292,16 +2290,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding; - final ui.Image screenshotImage = await binding.runAsync(() async { - final String base64Screenshot = await base64ScreenshotFuture as String; + final ui.Image screenshotImage = (await binding.runAsync(() async { + final String base64Screenshot = (await base64ScreenshotFuture)! as String; final ui.Codec codec = await ui.instantiateImageCodec(base64.decode(base64Screenshot)); final ui.FrameInfo frame = await codec.getNextFrame(); return frame.image; - }, additionalTime: const Duration(seconds: 11)); + }, additionalTime: const Duration(seconds: 11)))!; await expectLater( screenshotImage, - matchesReferenceImage(await clipRectScreenshot), + matchesReferenceImage((await clipRectScreenshot)!), skip: !isLinux, ); @@ -2341,7 +2339,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { }); test('ext.flutter.inspector.structuredErrors', () async { - List> flutterErrorEvents = service.getEventsDispatched('Flutter.Error'); + List> flutterErrorEvents = service.getEventsDispatched('Flutter.Error'); expect(flutterErrorEvents, isEmpty); final FlutterExceptionHandler oldHandler = FlutterError.presentError; @@ -2364,7 +2362,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(flutterErrorEvents, hasLength(1)); // Validate the error contents. - Map error = flutterErrorEvents.first; + Map error = flutterErrorEvents.first; expect(error['description'], 'Exception caught by rendering library'); expect(error['children'], isEmpty); @@ -2390,7 +2388,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(error['renderedErrorText'], startsWith('Another exception was thrown:')); // Reloads the app. - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding; // We need the runTest to setup the fake async in the test binding. await binding.runTest(() async { @@ -2482,7 +2480,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ), ); - final RenderBox box = key.currentContext.findRenderObject() as RenderBox; + final RenderBox box = key.currentContext!.findRenderObject()! as RenderBox; expect(box.localToGlobal(Offset.zero), const Offset(123.0, 456.0)); await expectLater( @@ -2569,8 +2567,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ), ); - final RenderBox box1 = key1.currentContext.findRenderObject() as RenderBox; - final RenderBox box2 = key2.currentContext.findRenderObject() as RenderBox; + final RenderBox box1 = key1.currentContext!.findRenderObject()! as RenderBox; + final RenderBox box2 = key2.currentContext!.findRenderObject()! as RenderBox; // Snapshot the positions of the two relevant boxes to ensure that taking // screenshots doesn't impact their positions. final Offset position1 = box1.localToGlobal(Offset.zero); @@ -2614,8 +2612,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Make sure taking screenshots hasn't modified the positions of the // TransformTarget or TransformFollower layers. - expect(identical(key1.currentContext.findRenderObject(), box1), isTrue); - expect(identical(key2.currentContext.findRenderObject(), box2), isTrue); + expect(identical(key1.currentContext!.findRenderObject(), box1), isTrue); + expect(identical(key2.currentContext!.findRenderObject(), box2), isTrue); expect(box1.localToGlobal(Offset.zero), equals(position1)); expect(box2.localToGlobal(Offset.zero), equals(position2)); }); @@ -2639,13 +2637,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); // Figure out the pubRootDirectory - final Map jsonObject = await service.testExtension( + final Map jsonObject = (await service.testExtension( 'getSelectedWidget', - {'arg': null, 'objectGroup': 'my-group'}, - ) as Map; - final Map creationLocation = jsonObject['creationLocation'] as Map; + {'objectGroup': 'my-group'}, + ))! as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); - final String file = creationLocation['file'] as String; + final String file = creationLocation['file']! as String; expect(file, endsWith('widget_inspector_test.dart')); final List segments = Uri.parse(file).pathSegments; // Strip a couple subdirectories away to generate a plausible pub rootdirectory. @@ -2657,7 +2655,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final List childrenOfMaterialApp = childrenOfRoot.first['children'] as List; final Map scaffold = childrenOfMaterialApp.first as Map; expect(scaffold['description'], 'Scaffold'); - final String objectId = scaffold['objectId'] as String; + final String objectId = scaffold['objectId']! as String; final String details = service.getDetailsSubtree(objectId, 'foo2'); final List detailedChildren = json.decode(details)['children'] as List; @@ -2668,7 +2666,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { appBars.add(child); } if (child.containsKey('children')) { - visitChildren(child['children'] as List); + visitChildren(child['children']! as List); } } } @@ -2708,10 +2706,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { addAdditionalPropertiesCallback: (DiagnosticsNode node, InspectorSerializationDelegate delegate) { final Map additionalJson = {}; - final Object value = node.value; + final Object? value = node.value; if (value is Element) { additionalJson['renderObject'] = - value.renderObject.toDiagnosticsNode().toJsonMap( + value.renderObject!.toDiagnosticsNode().toJsonMap( delegate.copyWith(subtreeDepth: 0), ); } @@ -2719,11 +2717,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { return additionalJson; }, ); - final Map json = node.toJsonMap(delegate); + final Map json = node.toJsonMap(delegate); expect(json['callbackExecuted'], true); expect(json.containsKey('renderObject'), true); expect(json['renderObject'], isA>()); - final Map renderObjectJson = json['renderObject'] as Map; + final Map renderObjectJson = json['renderObject']! as Map; expect(renderObjectJson['description'], startsWith('RenderFlex')); final InspectorSerializationDelegate emptyDelegate = @@ -2760,7 +2758,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ); - final Element element = key.currentContext as Element; + final Element element = key.currentContext! as Element; expect(debugIsLocalCreationLocation(element), isTrue); expect(debugIsLocalCreationLocation(element.widget), isTrue); @@ -2778,8 +2776,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { } void addToKnownLocationsMap({ - @required Map knownLocations, - @required Map> newLocations, + required Map knownLocations, + required Map> newLocations, }) { newLocations.forEach((String file, List entries) { assert(entries.length % 3 == 0); diff --git a/packages/flutter/test/widgets/wrap_test.dart b/packages/flutter/test/widgets/wrap_test.dart index 0ceefa6dde..4f09a6ff9f 100644 --- a/packages/flutter/test/widgets/wrap_test.dart +++ b/packages/flutter/test/widgets/wrap_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/rendering.dart'; import 'package:flutter/widgets.dart';