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) {
...@@ -90,4 +88,4 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect ...@@ -90,4 +88,4 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect
} }
}); });
} }
} }
\ No newline at end of file
...@@ -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';
import 'dart:math'; import 'dart:math';
...@@ -22,7 +20,7 @@ import 'widget_inspector_test_utils.dart'; ...@@ -22,7 +20,7 @@ import 'widget_inspector_test_utils.dart';
// columns will impact whether tests pass. // columns will impact whether tests pass.
class ClockDemo extends StatefulWidget { class ClockDemo extends StatefulWidget {
const ClockDemo({ Key key }) : super(key: key); const ClockDemo({ Key? key }) : super(key: key);
@override @override
_ClockDemoState createState() => _ClockDemoState(); _ClockDemoState createState() => _ClockDemoState();
} }
...@@ -60,7 +58,7 @@ class _ClockDemoState extends State<ClockDemo> { ...@@ -60,7 +58,7 @@ class _ClockDemoState extends State<ClockDemo> {
class ClockText extends StatefulWidget { class ClockText extends StatefulWidget {
const ClockText({ const ClockText({
Key key, Key? key,
this.utcOffset = 0, this.utcOffset = 0,
}) : super(key: key); }) : super(key: key);
...@@ -71,7 +69,7 @@ class ClockText extends StatefulWidget { ...@@ -71,7 +69,7 @@ class ClockText extends StatefulWidget {
} }
class _ClockTextState extends State<ClockText> { class _ClockTextState extends State<ClockText> {
DateTime currentTime = DateTime.now(); DateTime? currentTime = DateTime.now();
void updateTime() { void updateTime() {
setState(() { setState(() {
...@@ -91,7 +89,7 @@ class _ClockTextState extends State<ClockText> { ...@@ -91,7 +89,7 @@ class _ClockTextState extends State<ClockText> {
return const Text('stopped'); return const Text('stopped');
} }
return Text( return Text(
currentTime currentTime!
.toUtc() .toUtc()
.add(Duration(hours: widget.utcOffset)) .add(Duration(hours: widget.utcOffset))
.toIso8601String(), .toIso8601String(),
...@@ -110,7 +108,7 @@ class CyclicDiagnostic extends DiagnosticableTree { ...@@ -110,7 +108,7 @@ class CyclicDiagnostic extends DiagnosticableTree {
CyclicDiagnostic(this.name); CyclicDiagnostic(this.name);
// Field used to create cyclic relationships. // Field used to create cyclic relationships.
CyclicDiagnostic related; CyclicDiagnostic? related;
final List<DiagnosticsNode> children = <DiagnosticsNode>[]; final List<DiagnosticsNode> children = <DiagnosticsNode>[];
final String name; final String name;
...@@ -137,10 +135,10 @@ class CyclicDiagnostic extends DiagnosticableTree { ...@@ -137,10 +135,10 @@ class CyclicDiagnostic extends DiagnosticableTree {
class _CreationLocation { class _CreationLocation {
const _CreationLocation({ const _CreationLocation({
@required this.file, required this.file,
@required this.line, required this.line,
@required this.column, required this.column,
@required this.id, required this.id,
}); });
final String file; final String file;
...@@ -205,8 +203,8 @@ class RenderRepaintBoundaryWithDebugPaint extends RenderRepaintBoundary { ...@@ -205,8 +203,8 @@ class RenderRepaintBoundaryWithDebugPaint extends RenderRepaintBoundary {
class RepaintBoundaryWithDebugPaint extends RepaintBoundary { class RepaintBoundaryWithDebugPaint extends RepaintBoundary {
/// Creates a widget that isolates repaints. /// Creates a widget that isolates repaints.
const RepaintBoundaryWithDebugPaint({ const RepaintBoundaryWithDebugPaint({
Key key, Key? key,
Widget child, Widget? child,
}) : super(key: key, child: child); }) : super(key: key, child: child);
@override @override
...@@ -216,7 +214,7 @@ class RepaintBoundaryWithDebugPaint extends RepaintBoundary { ...@@ -216,7 +214,7 @@ class RepaintBoundaryWithDebugPaint extends RepaintBoundary {
} }
int getChildLayerCount(OffsetLayer layer) { int getChildLayerCount(OffsetLayer layer) {
Layer child = layer.firstChild; Layer? child = layer.firstChild;
int count = 0; int count = 0;
while (child != null) { while (child != null) {
count++; count++;
...@@ -282,7 +280,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -282,7 +280,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
dynamic getInspectorState() => inspectorKey.currentState; dynamic getInspectorState() => inspectorKey.currentState;
String paragraphText(RenderParagraph paragraph) { String paragraphText(RenderParagraph paragraph) {
final TextSpan textSpan = paragraph.text as TextSpan; final TextSpan textSpan = paragraph.text as TextSpan;
return textSpan.text; return textSpan.text!;
} }
await tester.pumpWidget( await tester.pumpWidget(
...@@ -320,8 +318,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -320,8 +318,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// Tap intercepted by the inspector // Tap intercepted by the inspector
expect(log, equals(<String>[])); expect(log, equals(<String>[]));
final InspectorSelection selection = getInspectorState().selection as InspectorSelection; final InspectorSelection selection = getInspectorState().selection as InspectorSelection;
expect(paragraphText(selection.current as RenderParagraph), equals('TOP')); expect(paragraphText(selection.current! as RenderParagraph), equals('TOP'));
final RenderObject topButton = find.byKey(topButtonKey).evaluate().first.renderObject; final RenderObject topButton = find.byKey(topButtonKey).evaluate().first.renderObject!;
expect(selection.candidates, contains(topButton)); expect(selection.candidates, contains(topButton));
await tester.tap(find.text('TOP')); await tester.tap(find.text('TOP'));
...@@ -457,7 +455,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -457,7 +455,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final GlobalKey inspectorKey = GlobalKey(); final GlobalKey inspectorKey = GlobalKey();
final GlobalKey clickTarget = GlobalKey(); final GlobalKey clickTarget = GlobalKey();
Widget createSubtree({ double width, Key key }) { Widget createSubtree({ double? width, Key? key }) {
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
Positioned( Positioned(
...@@ -583,7 +581,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -583,7 +581,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
dynamic getInspectorState() => inspector1Key.currentState; dynamic getInspectorState() => inspector1Key.currentState;
String paragraphText(RenderParagraph paragraph) { String paragraphText(RenderParagraph paragraph) {
final TextSpan textSpan = paragraph.text as TextSpan; final TextSpan textSpan = paragraph.text as TextSpan;
return textSpan.text; return textSpan.text!;
} }
await tester.pumpWidget( await tester.pumpWidget(
...@@ -618,15 +616,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -618,15 +616,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final InspectorSelection selection = getInspectorState().selection as InspectorSelection; final InspectorSelection selection = getInspectorState().selection as InspectorSelection;
// The selection is static, so it may be initialized from previous tests. // 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.tap(find.text('Child 1'));
await tester.pump(); 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.tap(find.text('Child 2'));
await tester.pump(); 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', () { test('WidgetInspectorService null id', () {
...@@ -641,7 +639,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -641,7 +639,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
const String group1 = 'group-1'; const String group1 = 'group-1';
const String group2 = 'group-2'; const String group2 = 'group-2';
const String group3 = 'group-3'; 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, group2), equals(aId));
expect(service.toId(a, group3), equals(aId)); expect(service.toId(a, group3), equals(aId));
service.disposeGroup(group1); service.disposeGroup(group1);
...@@ -657,8 +655,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -657,8 +655,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Object b = Object(); final Object b = Object();
const String group1 = 'group-1'; const String group1 = 'group-1';
const String group2 = 'group-2'; const String group2 = 'group-2';
final String aId = service.toId(a, group1); final String? aId = service.toId(a, group1);
final String bId = service.toId(b, group1); final String? bId = service.toId(b, group1);
expect(service.toId(a, group2), equals(aId)); expect(service.toId(a, group2), equals(aId));
service.disposeId(bId, group1); service.disposeId(bId, group1);
expect(() => service.toObject(bId), throwsFlutterError); expect(() => service.toObject(bId), throwsFlutterError);
...@@ -672,10 +670,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -672,10 +670,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
const String group = 'test-group'; const String group = 'test-group';
const Text widget = Text('a', textDirection: TextDirection.ltr); const Text widget = Text('a', textDirection: TextDirection.ltr);
service.disposeAllGroups(); service.disposeAllGroups();
final String id = service.toId(widget, group); final String id = service.toId(widget, group)!;
expect(service.toObjectForSourceLocation(id), equals(widget)); expect(service.toObjectForSourceLocation(id), equals(widget));
final Element element = widget.createElement(); 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(service.toObjectForSourceLocation(elementId), equals(widget));
expect(element, isNot(equals(widget))); expect(element, isNot(equals(widget)));
service.disposeGroup(group); service.disposeGroup(group);
...@@ -693,10 +691,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -693,10 +691,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
const String group3 = 'group-3'; const String group3 = 'group-3';
service.disposeAllGroups(); service.disposeAllGroups();
final String aId = service.toId(a, group1); final String? aId = service.toId(a, group1);
final String bId = service.toId(b, group2); final String? bId = service.toId(b, group2);
final String cId = service.toId(c, group3); final String? cId = service.toId(c, group3);
final String dId = service.toId(d, group1); final String? dId = service.toId(d, group1);
// Make sure we get a consistent id if we add the object to a group multiple // Make sure we get a consistent id if we add the object to a group multiple
// times. // times.
expect(aId, equals(service.toId(a, group1))); expect(aId, equals(service.toId(a, group1)));
...@@ -745,7 +743,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -745,7 +743,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.setSelection(elementB.renderObject); service.setSelection(elementB.renderObject);
expect(selectionChangedCount, equals(2)); expect(selectionChangedCount, equals(2));
expect(service.selection.current, equals(elementB.renderObject)); 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'); service.setSelection('invalid selection');
expect(selectionChangedCount, equals(2)); expect(selectionChangedCount, equals(2));
...@@ -779,11 +777,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -779,11 +777,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.disposeAllGroups(); service.disposeAllGroups();
final Element elementB = find.text('b').evaluate().first; final Element elementB = find.text('b').evaluate().first;
final String bId = service.toId(elementB, group); final String bId = service.toId(elementB, group)!;
final Object jsonList = json.decode(service.getParentChain(bId, group)); final Object? jsonList = json.decode(service.getParentChain(bId, group));
expect(jsonList, isList); expect(jsonList, isList);
final List<Object> chainElements = jsonList as List<Object>; final List<Object> chainElements = jsonList! as List<Object>;
final List<Element> expectedChain = elementB.debugGetDiagnosticChain()?.reversed?.toList(); final List<Element> expectedChain = elementB.debugGetDiagnosticChain().reversed.toList();
// Sanity check that the chain goes back to the root. // Sanity check that the chain goes back to the root.
expect(expectedChain.first, tester.binding.renderViewElement); expect(expectedChain.first, tester.binding.renderViewElement);
...@@ -793,12 +791,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -793,12 +791,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Map<String, Object> chainNode = chainElements[i] as Map<String, Object>; final Map<String, Object> chainNode = chainElements[i] as Map<String, Object>;
final Element element = expectedChain[i]; final Element element = expectedChain[i];
expect(chainNode['node'], isMap); expect(chainNode['node'], isMap);
final Map<String, Object> jsonNode = chainNode['node'] as Map<String, Object>; final Map<String, Object> jsonNode = chainNode['node']! as Map<String, Object>;
expect(service.toObject(jsonNode['valueId'] as String), equals(element)); expect(service.toObject(jsonNode['valueId']! as String), equals(element));
expect(service.toObject(jsonNode['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(jsonNode['objectId']! as String), isA<DiagnosticsNode>());
expect(chainNode['children'], isList); expect(chainNode['children'], isList);
final List<Object> jsonChildren = chainNode['children'] as List<Object>; final List<Object> jsonChildren = chainNode['children']! as List<Object>;
final List<Element> childrenElements = <Element>[]; final List<Element> childrenElements = <Element>[];
element.visitChildren(childrenElements.add); element.visitChildren(childrenElements.add);
expect(jsonChildren.length, equals(childrenElements.length)); expect(jsonChildren.length, equals(childrenElements.length));
...@@ -810,8 +808,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -810,8 +808,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
for (int j = 0; j < childrenElements.length; j += 1) { for (int j = 0; j < childrenElements.length; j += 1) {
expect(jsonChildren[j], isMap); expect(jsonChildren[j], isMap);
final Map<String, Object> childJson = jsonChildren[j] as Map<String, Object>; final Map<String, Object> childJson = jsonChildren[j] as Map<String, Object>;
expect(service.toObject(childJson['valueId'] as String), equals(childrenElements[j])); expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j]));
expect(service.toObject(childJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(childJson['objectId']! as String), isA<DiagnosticsNode>());
} }
} }
}); });
...@@ -820,15 +818,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -820,15 +818,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode();
const String group = 'group'; const String group = 'group';
service.disposeAllGroups(); service.disposeAllGroups();
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final List<Object> propertiesJson = json.decode(service.getProperties(id, group)) as List<Object>; final List<Object> propertiesJson = json.decode(service.getProperties(id, group)) as List<Object>;
final List<DiagnosticsNode> properties = diagnostic.getProperties(); final List<DiagnosticsNode> properties = diagnostic.getProperties();
expect(properties, isNotEmpty); expect(properties, isNotEmpty);
expect(propertiesJson.length, equals(properties.length)); expect(propertiesJson.length, equals(properties.length));
for (int i = 0; i < propertiesJson.length; ++i) { for (int i = 0; i < propertiesJson.length; ++i) {
final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>; final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>;
expect(service.toObject(propertyJson['valueId'] as String), equals(properties[i].value)); expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value));
expect(service.toObject(propertyJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(propertyJson['objectId']! as String), isA<DiagnosticsNode>());
} }
}); });
...@@ -849,15 +847,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -849,15 +847,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
); );
final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode();
service.disposeAllGroups(); service.disposeAllGroups();
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final List<Object> propertiesJson = json.decode(service.getChildren(id, group)) as List<Object>; final List<Object> propertiesJson = json.decode(service.getChildren(id, group)) as List<Object>;
final List<DiagnosticsNode> children = diagnostic.getChildren(); final List<DiagnosticsNode> children = diagnostic.getChildren();
expect(children.length, equals(3)); expect(children.length, equals(3));
expect(propertiesJson.length, equals(children.length)); expect(propertiesJson.length, equals(children.length));
for (int i = 0; i < propertiesJson.length; ++i) { for (int i = 0; i < propertiesJson.length; ++i) {
final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>; final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>;
expect(service.toObject(propertyJson['valueId'] as String), equals(children[i].value)); expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value));
expect(service.toObject(propertyJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(propertyJson['objectId']! as String), isA<DiagnosticsNode>());
} }
}); });
...@@ -881,21 +879,21 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -881,21 +879,21 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.setPubRootDirectories(<String>[]); service.setPubRootDirectories(<String>[]);
service.setSelection(elementA, 'my-group'); service.setSelection(elementA, 'my-group');
final Map<String, Object> jsonA = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; final Map<String, Object> jsonA = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
final Map<String, Object> creationLocationA = jsonA['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocationA = jsonA['creationLocation']! as Map<String, Object>;
expect(creationLocationA, isNotNull); expect(creationLocationA, isNotNull);
final String fileA = creationLocationA['file'] as String; final String fileA = creationLocationA['file']! as String;
final int lineA = creationLocationA['line'] as int; final int lineA = creationLocationA['line']! as int;
final int columnA = creationLocationA['column'] as int; final int columnA = creationLocationA['column']! as int;
final List<Object> parameterLocationsA = creationLocationA['parameterLocations'] as List<Object>; final List<Object> parameterLocationsA = creationLocationA['parameterLocations']! as List<Object>;
service.setSelection(elementB, 'my-group'); service.setSelection(elementB, 'my-group');
final Map<String, Object> jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; final Map<String, Object> jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
final Map<String, Object> creationLocationB = jsonB['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocationB = jsonB['creationLocation']! as Map<String, Object>;
expect(creationLocationB, isNotNull); expect(creationLocationB, isNotNull);
final String fileB = creationLocationB['file'] as String; final String fileB = creationLocationB['file']! as String;
final int lineB = creationLocationB['line'] as int; final int lineB = creationLocationB['line']! as int;
final int columnB = creationLocationB['column'] as int; final int columnB = creationLocationB['column']! as int;
final List<Object> parameterLocationsB = creationLocationB['parameterLocations'] as List<Object>; final List<Object> parameterLocationsB = creationLocationB['parameterLocations']! as List<Object>;
expect(fileA, endsWith('widget_inspector_test.dart')); expect(fileA, endsWith('widget_inspector_test.dart'));
expect(fileA, equals(fileB)); expect(fileA, equals(fileB));
// We don't hardcode the actual lines the widgets are created on as that // We don't hardcode the actual lines the widgets are created on as that
...@@ -936,13 +934,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -936,13 +934,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
), ),
); );
final Element elementA = find.text('a').evaluate().first; final Element elementA = find.text('a').evaluate().first;
String pubRootTest; late String pubRootTest;
if (widgetTracked) { if (widgetTracked) {
final Map<String, Object> jsonObject = json.decode( final Map<String, Object> jsonObject = json.decode(
service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
final Map<String, Object> creationLocation = jsonObject['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); 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(fileA, endsWith('widget_inspector_test.dart'));
expect(jsonObject, isNot(contains('createdByLocalProject'))); expect(jsonObject, isNot(contains('createdByLocalProject')));
final List<String> segments = Uri final List<String> segments = Uri
...@@ -998,13 +996,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -998,13 +996,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
), ),
); );
final Element elementA = find.text('a').evaluate().first; final Element elementA = find.text('a').evaluate().first;
String pubRootTest; late String pubRootTest;
if (widgetTracked) { if (widgetTracked) {
final Map<String, Object> jsonObject = json.decode( final Map<String, Object> jsonObject = json.decode(
service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
final Map<String, Object> creationLocation = jsonObject['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); 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(fileA, endsWith('widget_inspector_test.dart'));
expect(jsonObject, isNot(contains('createdByLocalProject'))); expect(jsonObject, isNot(contains('createdByLocalProject')));
final List<String> segments = Uri final List<String> segments = Uri
...@@ -1064,9 +1062,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1064,9 +1062,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.setPubRootDirectories(<String>[]); service.setPubRootDirectories(<String>[]);
service.setSelection(elementA, 'my-group'); service.setSelection(elementA, 'my-group');
Map<String, Object> jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; Map<String, Object> jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
Map<String, Object> creationLocation = jsonObject['creationLocation'] as Map<String, Object>; Map<String, Object> creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); 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(fileA, endsWith('widget_inspector_test.dart'));
expect(jsonObject, isNot(contains('createdByLocalProject'))); expect(jsonObject, isNot(contains('createdByLocalProject')));
final List<String> segments = Uri.parse(fileA).pathSegments; final List<String> segments = Uri.parse(fileA).pathSegments;
...@@ -1103,11 +1101,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1103,11 +1101,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.setPubRootDirectories(<String>[pubRootTest]); service.setPubRootDirectories(<String>[pubRootTest]);
jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
expect(jsonObject, isNot(contains('createdByLocalProject'))); expect(jsonObject, isNot(contains('createdByLocalProject')));
creationLocation = jsonObject['creationLocation'] as Map<String, Object>; creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
// This RichText widget is created by the build method of the Text widget // This RichText widget is created by the build method of the Text widget
// thus the creation location is in text.dart not basic.dart // thus the creation location is in text.dart not basic.dart
final List<String> pathSegmentsFramework = Uri.parse(creationLocation['file'] as String).pathSegments; final List<String> pathSegmentsFramework = Uri.parse(creationLocation['file']! as String).pathSegments;
expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart')); expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart'));
// Strip off /src/widgets/text.dart. // Strip off /src/widgets/text.dart.
...@@ -1129,7 +1127,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1129,7 +1127,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
const String group1 = 'group-1'; const String group1 = 'group-1';
const String group2 = 'group-2'; const String group2 = 'group-2';
const String group3 = 'group-3'; 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, group2), equals(aId));
expect(service.toId(a, group3), equals(aId)); expect(service.toId(a, group3), equals(aId));
await service.testExtension('disposeGroup', <String, String>{'objectGroup': group1}); await service.testExtension('disposeGroup', <String, String>{'objectGroup': group1});
...@@ -1144,8 +1142,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1144,8 +1142,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Object b = Object(); final Object b = Object();
const String group1 = 'group-1'; const String group1 = 'group-1';
const String group2 = 'group-2'; const String group2 = 'group-2';
final String aId = service.toId(a, group1); final String aId = service.toId(a, group1)!;
final String bId = service.toId(b, group1); final String bId = service.toId(b, group1)!;
expect(service.toId(a, group2), equals(aId)); expect(service.toId(a, group2), equals(aId));
await service.testExtension('disposeId', <String, String>{'arg': bId, 'objectGroup': group1}); await service.testExtension('disposeId', <String, String>{'arg': bId, 'objectGroup': group1});
expect(() => service.toObject(bId), throwsFlutterError); expect(() => service.toObject(bId), throwsFlutterError);
...@@ -1186,13 +1184,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1186,13 +1184,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.setSelection(elementB.renderObject); service.setSelection(elementB.renderObject);
expect(selectionChangedCount, equals(2)); expect(selectionChangedCount, equals(2));
expect(service.selection.current, equals(elementB.renderObject)); 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'); service.setSelection('invalid selection');
expect(selectionChangedCount, equals(2)); expect(selectionChangedCount, equals(2));
expect(service.selection.current, equals(elementB.renderObject)); expect(service.selection.current, equals(elementB.renderObject));
await service.testExtension('setSelectionById', <String, String>{'arg': service.toId(elementA, 'my-group'), 'objectGroup': 'my-group'}); await service.testExtension('setSelectionById', <String, String>{'arg': service.toId(elementA, 'my-group')!, 'objectGroup': 'my-group'});
expect(selectionChangedCount, equals(3)); expect(selectionChangedCount, equals(3));
expect(service.selection.currentElement, equals(elementA)); expect(service.selection.currentElement, equals(elementA));
expect(service.selection.current, equals(elementA.renderObject)); expect(service.selection.current, equals(elementA.renderObject));
...@@ -1219,11 +1217,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1219,11 +1217,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
); );
final Element elementB = find.text('b').evaluate().first; final Element elementB = find.text('b').evaluate().first;
final String bId = service.toId(elementB, group); final String bId = service.toId(elementB, group)!;
final Object jsonList = await service.testExtension('getParentChain', <String, String>{'arg': bId, 'objectGroup': group}); final Object? jsonList = await service.testExtension('getParentChain', <String, String>{'arg': bId, 'objectGroup': group});
expect(jsonList, isList); expect(jsonList, isList);
final List<Object> chainElements = jsonList as List<Object>; final List<Object> chainElements = jsonList! as List<Object>;
final List<Element> expectedChain = elementB.debugGetDiagnosticChain()?.reversed?.toList(); final List<Element> expectedChain = elementB.debugGetDiagnosticChain().reversed.toList();
// Sanity check that the chain goes back to the root. // Sanity check that the chain goes back to the root.
expect(expectedChain.first, tester.binding.renderViewElement); expect(expectedChain.first, tester.binding.renderViewElement);
...@@ -1233,12 +1231,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1233,12 +1231,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Map<String, Object> chainNode = chainElements[i] as Map<String, Object>; final Map<String, Object> chainNode = chainElements[i] as Map<String, Object>;
final Element element = expectedChain[i]; final Element element = expectedChain[i];
expect(chainNode['node'], isMap); expect(chainNode['node'], isMap);
final Map<String, Object> jsonNode = chainNode['node'] as Map<String, Object>; final Map<String, Object> jsonNode = chainNode['node']! as Map<String, Object>;
expect(service.toObject(jsonNode['valueId'] as String), equals(element)); expect(service.toObject(jsonNode['valueId']! as String), equals(element));
expect(service.toObject(jsonNode['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(jsonNode['objectId']! as String), isA<DiagnosticsNode>());
expect(chainNode['children'], isList); expect(chainNode['children'], isList);
final List<Object> jsonChildren = chainNode['children'] as List<Object>; final List<Object> jsonChildren = chainNode['children']! as List<Object>;
final List<Element> childrenElements = <Element>[]; final List<Element> childrenElements = <Element>[];
element.visitChildren(childrenElements.add); element.visitChildren(childrenElements.add);
expect(jsonChildren.length, equals(childrenElements.length)); expect(jsonChildren.length, equals(childrenElements.length));
...@@ -1250,8 +1248,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1250,8 +1248,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
for (int j = 0; j < childrenElements.length; j += 1) { for (int j = 0; j < childrenElements.length; j += 1) {
expect(jsonChildren[j], isMap); expect(jsonChildren[j], isMap);
final Map<String, Object> childJson = jsonChildren[j] as Map<String, Object>; final Map<String, Object> childJson = jsonChildren[j] as Map<String, Object>;
expect(service.toObject(childJson['valueId'] as String), equals(childrenElements[j])); expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j]));
expect(service.toObject(childJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(childJson['objectId']! as String), isA<DiagnosticsNode>());
} }
} }
}); });
...@@ -1259,15 +1257,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1259,15 +1257,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
test('ext.flutter.inspector.getProperties', () async { test('ext.flutter.inspector.getProperties', () async {
final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode();
const String group = 'group'; const String group = 'group';
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final List<Object> propertiesJson = await service.testExtension('getProperties', <String, String>{'arg': id, 'objectGroup': group}) as List<Object>; final List<Object> propertiesJson = (await service.testExtension('getProperties', <String, String>{'arg': id, 'objectGroup': group}))! as List<Object>;
final List<DiagnosticsNode> properties = diagnostic.getProperties(); final List<DiagnosticsNode> properties = diagnostic.getProperties();
expect(properties, isNotEmpty); expect(properties, isNotEmpty);
expect(propertiesJson.length, equals(properties.length)); expect(propertiesJson.length, equals(properties.length));
for (int i = 0; i < propertiesJson.length; ++i) { for (int i = 0; i < propertiesJson.length; ++i) {
final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>; final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>;
expect(service.toObject(propertyJson['valueId'] as String), equals(properties[i].value)); expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value));
expect(service.toObject(propertyJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(propertyJson['objectId']! as String), isA<DiagnosticsNode>());
} }
}); });
...@@ -1287,15 +1285,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1287,15 +1285,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
), ),
); );
final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode();
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final List<Object> propertiesJson = await service.testExtension('getChildren', <String, String>{'arg': id, 'objectGroup': group}) as List<Object>; final List<Object> propertiesJson = (await service.testExtension('getChildren', <String, String>{'arg': id, 'objectGroup': group}))! as List<Object>;
final List<DiagnosticsNode> children = diagnostic.getChildren(); final List<DiagnosticsNode> children = diagnostic.getChildren();
expect(children.length, equals(3)); expect(children.length, equals(3));
expect(propertiesJson.length, equals(children.length)); expect(propertiesJson.length, equals(children.length));
for (int i = 0; i < propertiesJson.length; ++i) { for (int i = 0; i < propertiesJson.length; ++i) {
final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>; final Map<String, Object> propertyJson = propertiesJson[i] as Map<String, Object>;
expect(service.toObject(propertyJson['valueId'] as String), equals(children[i].value)); expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value));
expect(service.toObject(propertyJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(propertyJson['objectId']! as String), isA<DiagnosticsNode>());
} }
}); });
...@@ -1315,20 +1313,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1315,20 +1313,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
), ),
); );
final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode();
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final List<Object> childrenJson = await service.testExtension('getChildrenDetailsSubtree', <String, String>{'arg': id, 'objectGroup': group}) as List<Object>; final List<Object> childrenJson = (await service.testExtension('getChildrenDetailsSubtree', <String, String>{'arg': id, 'objectGroup': group}))! as List<Object>;
final List<DiagnosticsNode> children = diagnostic.getChildren(); final List<DiagnosticsNode> children = diagnostic.getChildren();
expect(children.length, equals(3)); expect(children.length, equals(3));
expect(childrenJson.length, equals(children.length)); expect(childrenJson.length, equals(children.length));
for (int i = 0; i < childrenJson.length; ++i) { for (int i = 0; i < childrenJson.length; ++i) {
final Map<String, Object> childJson = childrenJson[i] as Map<String, Object>; final Map<String, Object> childJson = childrenJson[i] as Map<String, Object>;
expect(service.toObject(childJson['valueId'] as String), equals(children[i].value)); expect(service.toObject(childJson['valueId']! as String), equals(children[i].value));
expect(service.toObject(childJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(childJson['objectId']! as String), isA<DiagnosticsNode>());
final List<Object> propertiesJson = childJson['properties'] as List<Object>; final List<Object> propertiesJson = childJson['properties']! as List<Object>;
final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId'] as String) as DiagnosticsNode; final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode;
final List<DiagnosticsNode> expectedProperties = diagnosticsNode.getProperties(); final List<DiagnosticsNode> expectedProperties = diagnosticsNode.getProperties();
for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) { for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) {
final Object property = service.toObject(propertyJson['objectId'] as String); final Object? property = service.toObject(propertyJson['objectId']! as String);
expect(property, isA<DiagnosticsNode>()); expect(property, isA<DiagnosticsNode>());
expect(expectedProperties, contains(property)); expect(expectedProperties, contains(property));
} }
...@@ -1351,37 +1349,37 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1351,37 +1349,37 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
), ),
); );
final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode();
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final Map<String, Object> subtreeJson = await service.testExtension('getDetailsSubtree', <String, String>{'arg': id, 'objectGroup': group}) as Map<String, Object>; final Map<String, Object> subtreeJson = (await service.testExtension('getDetailsSubtree', <String, String>{'arg': id, 'objectGroup': group}))! as Map<String, Object>;
expect(subtreeJson['objectId'], equals(id)); expect(subtreeJson['objectId'], equals(id));
final List<Object> childrenJson = subtreeJson['children'] as List<Object>; final List<Object> childrenJson = subtreeJson['children']! as List<Object>;
final List<DiagnosticsNode> children = diagnostic.getChildren(); final List<DiagnosticsNode> children = diagnostic.getChildren();
expect(children.length, equals(3)); expect(children.length, equals(3));
expect(childrenJson.length, equals(children.length)); expect(childrenJson.length, equals(children.length));
for (int i = 0; i < childrenJson.length; ++i) { for (int i = 0; i < childrenJson.length; ++i) {
final Map<String, Object> childJson = childrenJson[i] as Map<String, Object>; final Map<String, Object> childJson = childrenJson[i] as Map<String, Object>;
expect(service.toObject(childJson['valueId'] as String), equals(children[i].value)); expect(service.toObject(childJson['valueId']! as String), equals(children[i].value));
expect(service.toObject(childJson['objectId'] as String), isA<DiagnosticsNode>()); expect(service.toObject(childJson['objectId']! as String), isA<DiagnosticsNode>());
final List<Object> propertiesJson = childJson['properties'] as List<Object>; final List<Object> propertiesJson = childJson['properties']! as List<Object>;
for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) { for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) {
expect(propertyJson, isNot(contains('children'))); 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<DiagnosticsNode> expectedProperties = diagnosticsNode.getProperties(); final List<DiagnosticsNode> expectedProperties = diagnosticsNode.getProperties();
for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) { for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) {
final Object property = service.toObject(propertyJson['objectId'] as String); final Object property = service.toObject(propertyJson['objectId']! as String)!;
expect(property, isA<DiagnosticsNode>()); expect(property, isA<DiagnosticsNode>());
expect(expectedProperties, contains(property)); expect(expectedProperties, contains(property));
} }
} }
final Map<String, Object> deepSubtreeJson = await service.testExtension( final Map<String, Object> deepSubtreeJson = (await service.testExtension(
'getDetailsSubtree', 'getDetailsSubtree',
<String, String>{'arg': id, 'objectGroup': group, 'subtreeDepth': '3'}, <String, String>{'arg': id, 'objectGroup': group, 'subtreeDepth': '3'},
) as Map<String, Object>; ))! as Map<String, Object>;
final List<Object> deepChildrenJson = deepSubtreeJson['children'] as List<Object>; final List<Object> deepChildrenJson = deepSubtreeJson['children']! as List<Object>;
for (final Map<String, Object> childJson in deepChildrenJson.cast<Map<String, Object>>()) { for (final Map<String, Object> childJson in deepChildrenJson.cast<Map<String, Object>>()) {
final List<Object> propertiesJson = childJson['properties'] as List<Object>; final List<Object> propertiesJson = childJson['properties']! as List<Object>;
for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) { for (final Map<String, Object> propertyJson in propertiesJson.cast<Map<String, Object>>()) {
expect(propertyJson, contains('children')); expect(propertyJson, contains('children'));
} }
...@@ -1397,11 +1395,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1397,11 +1395,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
b.related = a; b.related = a;
final DiagnosticsNode diagnostic = a.toDiagnosticsNode(); final DiagnosticsNode diagnostic = a.toDiagnosticsNode();
final String id = service.toId(diagnostic, group); final String id = service.toId(diagnostic, group)!;
final Map<String, Object> subtreeJson = await service.testExtension('getDetailsSubtree', <String, String>{'arg': id, 'objectGroup': group}) as Map<String, Object>; final Map<String, Object> subtreeJson = (await service.testExtension('getDetailsSubtree', <String, String>{'arg': id, 'objectGroup': group}))! as Map<String, Object>;
expect(subtreeJson['objectId'], equals(id)); expect(subtreeJson['objectId'], equals(id));
expect(subtreeJson, contains('children')); expect(subtreeJson, contains('children'));
final List<Object> propertiesJson = subtreeJson['properties'] as List<Object>; final List<Object> propertiesJson = subtreeJson['properties']! as List<Object>;
expect(propertiesJson.length, equals(1)); expect(propertiesJson.length, equals(1));
final Map<String, Object> relatedProperty = propertiesJson.first as Map<String, Object>; final Map<String, Object> relatedProperty = propertiesJson.first as Map<String, Object>;
expect(relatedProperty['name'], equals('related')); expect(relatedProperty['name'], equals('related'));
...@@ -1409,7 +1407,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1409,7 +1407,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(relatedProperty, contains('isDiagnosticableValue')); expect(relatedProperty, contains('isDiagnosticableValue'));
expect(relatedProperty, isNot(contains('children'))); expect(relatedProperty, isNot(contains('children')));
expect(relatedProperty, contains('properties')); expect(relatedProperty, contains('properties'));
final List<Object> relatedWidgetProperties = relatedProperty['properties'] as List<Object>; final List<Object> relatedWidgetProperties = relatedProperty['properties']! as List<Object>;
expect(relatedWidgetProperties.length, equals(1)); expect(relatedWidgetProperties.length, equals(1));
final Map<String, Object> nestedRelatedProperty = relatedWidgetProperties.first as Map<String, Object>; final Map<String, Object> nestedRelatedProperty = relatedWidgetProperties.first as Map<String, Object>;
expect(nestedRelatedProperty['name'], equals('related')); expect(nestedRelatedProperty['name'], equals('related'));
...@@ -1442,22 +1440,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1442,22 +1440,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.disposeAllGroups(); service.disposeAllGroups();
await service.testExtension('setPubRootDirectories', <String, String>{}); await service.testExtension('setPubRootDirectories', <String, String>{});
service.setSelection(elementA, 'my-group'); service.setSelection(elementA, 'my-group');
final Map<String, Object> jsonA = await service.testExtension('getSelectedWidget', <String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; final Map<String, Object?> jsonA = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object?>;
await service.testExtension('setPubRootDirectories', <String, String>{}); await service.testExtension('setPubRootDirectories', <String, String>{});
Map<String, Object> rootJson = await service.testExtension('getRootWidgetSummaryTree', <String, String>{'objectGroup': group}) as Map<String, Object>; Map<String, Object> rootJson = (await service.testExtension('getRootWidgetSummaryTree', <String, String>{'objectGroup': group}))! as Map<String, Object>;
// We haven't yet properly specified which directories are summary tree // 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 // directories so we get an empty tree other than the root that is always
// included. // 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)); expect(rootWidget, equals(WidgetsBinding.instance?.renderViewElement));
List<Object> childrenJson = rootJson['children'] as List<Object>; List<Object> childrenJson = rootJson['children']! as List<Object>;
// There are no summary tree children. // There are no summary tree children.
expect(childrenJson.length, equals(0)); expect(childrenJson.length, equals(0));
final Map<String, Object> creationLocation = jsonA['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocation = jsonA['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
final String testFile = creationLocation['file'] as String; final String testFile = creationLocation['file']! as String;
expect(testFile, endsWith('widget_inspector_test.dart')); expect(testFile, endsWith('widget_inspector_test.dart'));
final List<String> segments = Uri.parse(testFile).pathSegments; final List<String> segments = Uri.parse(testFile).pathSegments;
// Strip a couple subdirectories away to generate a plausible pub root // Strip a couple subdirectories away to generate a plausible pub root
...@@ -1465,14 +1463,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1465,14 +1463,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final String pubRootTest = '/' + segments.take(segments.length - 2).join('/'); final String pubRootTest = '/' + segments.take(segments.length - 2).join('/');
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootTest}); await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootTest});
rootJson = await service.testExtension('getRootWidgetSummaryTree', <String, String>{'objectGroup': group}) as Map<String, Object>; rootJson = (await service.testExtension('getRootWidgetSummaryTree', <String, String>{'objectGroup': group}))! as Map<String, Object>;
childrenJson = rootJson['children'] as List<Object>; childrenJson = rootJson['children']! as List<Object>;
// The tree of nodes returned contains all widgets created directly by the // The tree of nodes returned contains all widgets created directly by the
// test. // test.
childrenJson = rootJson['children'] as List<Object>; childrenJson = rootJson['children']! as List<Object>;
expect(childrenJson.length, equals(1)); expect(childrenJson.length, equals(1));
List<Object> alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': rootJson['objectId'] as String, 'objectGroup': group}) as List<Object>; List<Object> alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': rootJson['objectId']! as String, 'objectGroup': group}))! as List<Object>;
expect(alternateChildrenJson.length, equals(1)); expect(alternateChildrenJson.length, equals(1));
Map<String, Object> childJson = childrenJson[0] as Map<String, Object>; Map<String, Object> childJson = childrenJson[0] as Map<String, Object>;
Map<String, Object> alternateChildJson = alternateChildrenJson[0] as Map<String, Object>; Map<String, Object> alternateChildJson = alternateChildrenJson[0] as Map<String, Object>;
...@@ -1480,8 +1478,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1480,8 +1478,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(alternateChildJson['description'], startsWith('Directionality')); expect(alternateChildJson['description'], startsWith('Directionality'));
expect(alternateChildJson['valueId'], equals(childJson['valueId'])); expect(alternateChildJson['valueId'], equals(childJson['valueId']));
childrenJson = childJson['children'] as List<Object>; childrenJson = childJson['children']! as List<Object>;
alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': childJson['objectId'] as String, 'objectGroup': group}) as List<Object>; alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List<Object>;
expect(alternateChildrenJson.length, equals(1)); expect(alternateChildrenJson.length, equals(1));
expect(childrenJson.length, equals(1)); expect(childrenJson.length, equals(1));
alternateChildJson = alternateChildrenJson[0] as Map<String, Object>; alternateChildJson = alternateChildrenJson[0] as Map<String, Object>;
...@@ -1489,10 +1487,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1489,10 +1487,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(childJson['description'], startsWith('Stack')); expect(childJson['description'], startsWith('Stack'));
expect(alternateChildJson['description'], startsWith('Stack')); expect(alternateChildJson['description'], startsWith('Stack'));
expect(alternateChildJson['valueId'], equals(childJson['valueId'])); expect(alternateChildJson['valueId'], equals(childJson['valueId']));
childrenJson = childJson['children'] as List<Object>; childrenJson = childJson['children']! as List<Object>;
childrenJson = childJson['children'] as List<Object>; childrenJson = childJson['children']! as List<Object>;
alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': childJson['objectId'] as String, 'objectGroup': group}) as List<Object>; alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List<Object>;
expect(alternateChildrenJson.length, equals(3)); expect(alternateChildrenJson.length, equals(3));
expect(childrenJson.length, equals(3)); expect(childrenJson.length, equals(3));
alternateChildJson = alternateChildrenJson[2] as Map<String, Object>; alternateChildJson = alternateChildrenJson[2] as Map<String, Object>;
...@@ -1500,7 +1498,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1500,7 +1498,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(childJson['description'], startsWith('Text')); expect(childJson['description'], startsWith('Text'));
expect(alternateChildJson['description'], startsWith('Text')); expect(alternateChildJson['description'], startsWith('Text'));
expect(alternateChildJson['valueId'], equals(childJson['valueId'])); expect(alternateChildJson['valueId'], equals(childJson['valueId']));
alternateChildrenJson = await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': childJson['objectId'] as String, 'objectGroup': group}) as List<Object>; alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', <String, String>{'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List<Object>;
expect(alternateChildrenJson.length , equals(0)); expect(alternateChildrenJson.length , equals(0));
expect(childJson['chidlren'], isNull); expect(childJson['chidlren'], isNull);
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag.
...@@ -1529,18 +1527,18 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1529,18 +1527,18 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.disposeAllGroups(); service.disposeAllGroups();
await service.testExtension('setPubRootDirectories', <String, String>{}); await service.testExtension('setPubRootDirectories', <String, String>{});
service.setSelection(elementA, 'my-group'); service.setSelection(elementA, 'my-group');
final Map<String, Object> jsonA = await service.testExtension('getSelectedWidget', <String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; final Map<String, Object> jsonA = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object>;
service.setSelection(richTextDiagnostic.value, 'my-group'); service.setSelection(richTextDiagnostic.value, 'my-group');
await service.testExtension('setPubRootDirectories', <String, String>{}); await service.testExtension('setPubRootDirectories', <String, String>{});
Map<String, Object> summarySelection = await service.testExtension('getSelectedSummaryWidget', <String, String>{'objectGroup': group}) as Map<String, Object>; Map<String, Object>? summarySelection = await service.testExtension('getSelectedSummaryWidget', <String, String>{'objectGroup': group}) as Map<String, Object>?;
// No summary selection because we haven't set the pub root directories // No summary selection because we haven't set the pub root directories
// yet to indicate what directories are in the summary tree. // yet to indicate what directories are in the summary tree.
expect(summarySelection, isNull); expect(summarySelection, isNull);
final Map<String, Object> creationLocation = jsonA['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocation = jsonA['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
final String testFile = creationLocation['file'] as String; final String testFile = creationLocation['file']! as String;
expect(testFile, endsWith('widget_inspector_test.dart')); expect(testFile, endsWith('widget_inspector_test.dart'));
final List<String> segments = Uri.parse(testFile).pathSegments; final List<String> segments = Uri.parse(testFile).pathSegments;
// Strip a couple subdirectories away to generate a plausible pub root // Strip a couple subdirectories away to generate a plausible pub root
...@@ -1548,16 +1546,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1548,16 +1546,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final String pubRootTest = '/' + segments.take(segments.length - 2).join('/'); final String pubRootTest = '/' + segments.take(segments.length - 2).join('/');
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootTest}); await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootTest});
summarySelection = await service.testExtension('getSelectedSummaryWidget', <String, String>{'objectGroup': group}) as Map<String, Object>; summarySelection = (await service.testExtension('getSelectedSummaryWidget', <String, String>{'objectGroup': group}))! as Map<String, Object>;
expect(summarySelection['valueId'], isNotNull); expect(summarySelection['valueId'], isNotNull);
// We got the Text element instead of the selected RichText element // We got the Text element instead of the selected RichText element
// because only the RichText element is part of the summary tree. // 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 // Verify tha the regular getSelectedWidget method still returns
// the RichText object not the Text element. // the RichText object not the Text element.
final Map<String, Object> regularSelection = await service.testExtension('getSelectedWidget', <String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; final Map<String, Object> regularSelection = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object>;
expect(service.toObject(regularSelection['valueId'] as String), richTextDiagnostic.value); expect(service.toObject(regularSelection['valueId']! as String), richTextDiagnostic.value);
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag.
testWidgets('ext.flutter.inspector creationLocation', (WidgetTester tester) async { testWidgets('ext.flutter.inspector creationLocation', (WidgetTester tester) async {
...@@ -1579,22 +1577,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1579,22 +1577,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.disposeAllGroups(); service.disposeAllGroups();
await service.testExtension('setPubRootDirectories', <String, String>{}); await service.testExtension('setPubRootDirectories', <String, String>{});
service.setSelection(elementA, 'my-group'); service.setSelection(elementA, 'my-group');
final Map<String, Object> jsonA = await service.testExtension('getSelectedWidget', <String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; final Map<String, Object> jsonA = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object>;
final Map<String, Object> creationLocationA = jsonA['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocationA = jsonA['creationLocation']! as Map<String, Object>;
expect(creationLocationA, isNotNull); expect(creationLocationA, isNotNull);
final String fileA = creationLocationA['file'] as String; final String fileA = creationLocationA['file']! as String;
final int lineA = creationLocationA['line'] as int; final int lineA = creationLocationA['line']! as int;
final int columnA = creationLocationA['column'] as int; final int columnA = creationLocationA['column']! as int;
final List<Object> parameterLocationsA = creationLocationA['parameterLocations'] as List<Object>; final List<Object> parameterLocationsA = creationLocationA['parameterLocations']! as List<Object>;
service.setSelection(elementB, 'my-group'); service.setSelection(elementB, 'my-group');
final Map<String, Object> jsonB = await service.testExtension('getSelectedWidget', <String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; final Map<String, Object> jsonB = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object>;
final Map<String, Object> creationLocationB = jsonB['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocationB = jsonB['creationLocation']! as Map<String, Object>;
expect(creationLocationB, isNotNull); expect(creationLocationB, isNotNull);
final String fileB = creationLocationB['file'] as String; final String fileB = creationLocationB['file']! as String;
final int lineB = creationLocationB['line'] as int; final int lineB = creationLocationB['line']! as int;
final int columnB = creationLocationB['column'] as int; final int columnB = creationLocationB['column']! as int;
final List<Object> parameterLocationsB = creationLocationB['parameterLocations'] as List<Object>; final List<Object> parameterLocationsB = creationLocationB['parameterLocations']! as List<Object>;
expect(fileA, endsWith('widget_inspector_test.dart')); expect(fileA, endsWith('widget_inspector_test.dart'));
expect(fileA, equals(fileB)); expect(fileA, equals(fileB));
// We don't hardcode the actual lines the widgets are created on as that // We don't hardcode the actual lines the widgets are created on as that
...@@ -1637,10 +1635,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1637,10 +1635,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
await service.testExtension('setPubRootDirectories', <String, String>{}); await service.testExtension('setPubRootDirectories', <String, String>{});
service.setSelection(elementA, 'my-group'); service.setSelection(elementA, 'my-group');
Map<String, Object> jsonObject = await service.testExtension('getSelectedWidget', <String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; Map<String, Object> jsonObject = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object>;
Map<String, Object> creationLocation = jsonObject['creationLocation'] as Map<String, Object>; Map<String, Object> creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); 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(fileA, endsWith('widget_inspector_test.dart'));
expect(jsonObject, isNot(contains('createdByLocalProject'))); expect(jsonObject, isNot(contains('createdByLocalProject')));
final List<String> segments = Uri.parse(fileA).pathSegments; final List<String> segments = Uri.parse(fileA).pathSegments;
...@@ -1678,11 +1676,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1678,11 +1676,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
service.setPubRootDirectories(<String>[pubRootTest]); service.setPubRootDirectories(<String>[pubRootTest]);
jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>; jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object>;
expect(jsonObject, isNot(contains('createdByLocalProject'))); expect(jsonObject, isNot(contains('createdByLocalProject')));
creationLocation = jsonObject['creationLocation'] as Map<String, Object>; creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
// This RichText widget is created by the build method of the Text widget // This RichText widget is created by the build method of the Text widget
// thus the creation location is in text.dart not basic.dart // thus the creation location is in text.dart not basic.dart
final List<String> pathSegmentsFramework = Uri.parse(creationLocation['file'] as String).pathSegments; final List<String> pathSegmentsFramework = Uri.parse(creationLocation['file']! as String).pathSegments;
expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart')); expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart'));
// Strip off /src/widgets/text.dart. // Strip off /src/widgets/text.dart.
...@@ -1707,13 +1705,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1707,13 +1705,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; final Element clockDemoElement = find.byType(ClockDemo).evaluate().first;
service.setSelection(clockDemoElement, 'my-group'); service.setSelection(clockDemoElement, 'my-group');
final Map<String, Object> jsonObject = await service.testExtension( final Map<String, Object> jsonObject = (await service.testExtension(
'getSelectedWidget', 'getSelectedWidget',
<String, String>{'arg': null, 'objectGroup': 'my-group'}, <String, String>{'objectGroup': 'my-group'},
) as Map<String, Object>; ))! as Map<String, Object>;
final Map<String, Object> creationLocation = jsonObject['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
final String file = creationLocation['file'] as String; final String file = creationLocation['file']! as String;
expect(file, endsWith('widget_inspector_test.dart')); expect(file, endsWith('widget_inspector_test.dart'));
final List<String> segments = Uri.parse(file).pathSegments; final List<String> segments = Uri.parse(file).pathSegments;
// Strip a couple subdirectories away to generate a plausible pub root // Strip a couple subdirectories away to generate a plausible pub root
...@@ -1723,7 +1721,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1723,7 +1721,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
await service.testExtension( await service.testExtension(
'setPubRootDirectories', <String, String>{'arg0': pubRootTest}); 'setPubRootDirectories', <String, String>{'arg0': pubRootTest});
final List<Map<Object, Object>> rebuildEvents = final List<Map<Object, Object?>> rebuildEvents =
service.getEventsDispatched('Flutter.RebuiltWidgets'); service.getEventsDispatched('Flutter.RebuiltWidgets');
expect(rebuildEvents, isEmpty); expect(rebuildEvents, isEmpty);
...@@ -1736,16 +1734,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1736,16 +1734,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
await tester.pump(); await tester.pump();
expect(rebuildEvents.length, equals(1)); expect(rebuildEvents.length, equals(1));
Map<Object, Object> event = rebuildEvents.removeLast(); Map<Object, Object?> event = rebuildEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
List<int> data = event['events'] as List<int>; List<int> data = event['events']! as List<int>;
expect(data.length, equals(14)); expect(data.length, equals(14));
final int numDataEntries = data.length ~/ 2; final int numDataEntries = data.length ~/ 2;
Map<String, List<int>> newLocations = event['newLocations'] as Map<String, List<int>>; Map<String, List<int>> newLocations = event['newLocations']! as Map<String, List<int>>;
expect(newLocations, isNotNull); expect(newLocations, isNotNull);
expect(newLocations.length, equals(1)); expect(newLocations.length, equals(1));
expect(newLocations.keys.first, equals(file)); expect(newLocations.keys.first, equals(file));
final List<int> locationsForFile = newLocations[file]; final List<int> locationsForFile = newLocations[file]!;
expect(locationsForFile.length, equals(21)); expect(locationsForFile.length, equals(21));
final int numLocationEntries = locationsForFile.length ~/ 3; final int numLocationEntries = locationsForFile.length ~/ 3;
expect(numLocationEntries, equals(numDataEntries)); expect(numLocationEntries, equals(numDataEntries));
...@@ -1779,7 +1777,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1779,7 +1777,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(rebuildEvents.length, equals(1)); expect(rebuildEvents.length, equals(1));
event = rebuildEvents.removeLast(); event = rebuildEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
data = event['events'] as List<int>; data = event['events']! as List<int>;
// No new locations were rebuilt. // No new locations were rebuilt.
expect(event, isNot(contains('newLocations'))); expect(event, isNot(contains('newLocations')));
...@@ -1788,19 +1786,19 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1788,19 +1786,19 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(data.length, equals(4)); expect(data.length, equals(4));
int id = data[0]; int id = data[0];
int count = data[1]; int count = data[1];
_CreationLocation location = knownLocations[id]; _CreationLocation location = knownLocations[id]!;
expect(location.file, equals(file)); expect(location.file, equals(file));
// ClockText widget. // ClockText widget.
expect(location.line, equals(55)); expect(location.line, equals(53));
expect(location.column, equals(9)); expect(location.column, equals(9));
expect(count, equals(1)); expect(count, equals(1));
id = data[2]; id = data[2];
count = data[3]; count = data[3];
location = knownLocations[id]; location = knownLocations[id]!;
expect(location.file, equals(file)); expect(location.file, equals(file));
// Text widget in _ClockTextState build method. // Text widget in _ClockTextState build method.
expect(location.line, equals(93)); expect(location.line, equals(91));
expect(location.column, equals(12)); expect(location.column, equals(12));
expect(count, equals(1)); expect(count, equals(1));
...@@ -1815,26 +1813,26 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1815,26 +1813,26 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(rebuildEvents.length, equals(1)); expect(rebuildEvents.length, equals(1));
event = rebuildEvents.removeLast(); event = rebuildEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
data = event['events'] as List<int>; data = event['events']! as List<int>;
// No new locations were rebuilt. // No new locations were rebuilt.
expect(event, isNot(contains('newLocations'))); expect(event, isNot(contains('newLocations')));
expect(data.length, equals(4)); expect(data.length, equals(4));
id = data[0]; id = data[0];
count = data[1]; count = data[1];
location = knownLocations[id]; location = knownLocations[id]!;
expect(location.file, equals(file)); expect(location.file, equals(file));
// ClockText widget. // ClockText widget.
expect(location.line, equals(55)); expect(location.line, equals(53));
expect(location.column, equals(9)); expect(location.column, equals(9));
expect(count, equals(3)); // 3 clock widget instances rebuilt. expect(count, equals(3)); // 3 clock widget instances rebuilt.
id = data[2]; id = data[2];
count = data[3]; count = data[3];
location = knownLocations[id]; location = knownLocations[id]!;
expect(location.file, equals(file)); expect(location.file, equals(file));
// Text widget in _ClockTextState build method. // Text widget in _ClockTextState build method.
expect(location.line, equals(93)); expect(location.line, equals(91));
expect(location.column, equals(12)); expect(location.column, equals(12));
expect(count, equals(3)); // 3 clock widget instances rebuilt. expect(count, equals(3)); // 3 clock widget instances rebuilt.
...@@ -1849,7 +1847,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1849,7 +1847,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(rebuildEvents.length, equals(1)); expect(rebuildEvents.length, equals(1));
event = rebuildEvents.removeLast(); event = rebuildEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
data = event['events'] as List<int>; data = event['events']! as List<int>;
// No new locations were rebuilt. // No new locations were rebuilt.
expect(event, isNot(contains('newLocations'))); expect(event, isNot(contains('newLocations')));
...@@ -1866,8 +1864,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1866,8 +1864,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(rebuildEvents.length, equals(1)); expect(rebuildEvents.length, equals(1));
event = rebuildEvents.removeLast(); event = rebuildEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
data = event['events'] as List<int>; data = event['events']! as List<int>;
newLocations = event['newLocations'] as Map<String, List<int>>; newLocations = event['newLocations']! as Map<String, List<int>>;
expect(data.length, equals(4)); expect(data.length, equals(4));
// The second pair in data is the previously unseen rebuild location. // The second pair in data is the previously unseen rebuild location.
...@@ -1903,13 +1901,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1903,13 +1901,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; final Element clockDemoElement = find.byType(ClockDemo).evaluate().first;
service.setSelection(clockDemoElement, 'my-group'); service.setSelection(clockDemoElement, 'my-group');
final Map<String, Object> jsonObject = await service.testExtension( final Map<String, Object> jsonObject = (await service.testExtension(
'getSelectedWidget', 'getSelectedWidget',
<String, String>{'arg': null, 'objectGroup': 'my-group'}) as Map<String, Object>; <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object>;
final Map<String, Object> creationLocation = final Map<String, Object> creationLocation =
jsonObject['creationLocation'] as Map<String, Object>; jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
final String file = creationLocation['file'] as String; final String file = creationLocation['file']! as String;
expect(file, endsWith('widget_inspector_test.dart')); expect(file, endsWith('widget_inspector_test.dart'));
final List<String> segments = Uri.parse(file).pathSegments; final List<String> segments = Uri.parse(file).pathSegments;
// Strip a couple subdirectories away to generate a plausible pub root // Strip a couple subdirectories away to generate a plausible pub root
...@@ -1919,7 +1917,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1919,7 +1917,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
await service.testExtension( await service.testExtension(
'setPubRootDirectories', <String, String>{'arg0': pubRootTest}); 'setPubRootDirectories', <String, String>{'arg0': pubRootTest});
final List<Map<Object, Object>> repaintEvents = final List<Map<Object, Object?>> repaintEvents =
service.getEventsDispatched('Flutter.RepaintWidgets'); service.getEventsDispatched('Flutter.RepaintWidgets');
expect(repaintEvents, isEmpty); expect(repaintEvents, isEmpty);
...@@ -1935,16 +1933,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1935,16 +1933,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
await tester.pump(); await tester.pump();
expect(repaintEvents.length, equals(1)); expect(repaintEvents.length, equals(1));
Map<Object, Object> event = repaintEvents.removeLast(); Map<Object, Object?> event = repaintEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
List<int> data = event['events'] as List<int>; List<int> data = event['events']! as List<int>;
expect(data.length, equals(18)); expect(data.length, equals(18));
final int numDataEntries = data.length ~/ 2; final int numDataEntries = data.length ~/ 2;
final Map<String, List<int>> newLocations = event['newLocations'] as Map<String, List<int>>; final Map<String, List<int>> newLocations = event['newLocations']! as Map<String, List<int>>;
expect(newLocations, isNotNull); expect(newLocations, isNotNull);
expect(newLocations.length, equals(1)); expect(newLocations.length, equals(1));
expect(newLocations.keys.first, equals(file)); expect(newLocations.keys.first, equals(file));
final List<int> locationsForFile = newLocations[file]; final List<int> locationsForFile = newLocations[file]!;
expect(locationsForFile.length, equals(27)); expect(locationsForFile.length, equals(27));
final int numLocationEntries = locationsForFile.length ~/ 3; final int numLocationEntries = locationsForFile.length ~/ 3;
expect(numLocationEntries, equals(numDataEntries)); expect(numLocationEntries, equals(numDataEntries));
...@@ -1979,7 +1977,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -1979,7 +1977,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(repaintEvents.length, equals(1)); expect(repaintEvents.length, equals(1));
event = repaintEvents.removeLast(); event = repaintEvents.removeLast();
expect(event['startTime'], isA<int>()); expect(event['startTime'], isA<int>());
data = event['events'] as List<int>; data = event['events']! as List<int>;
// No new locations were rebuilt. // No new locations were rebuilt.
expect(event, isNot(contains('newLocations'))); expect(event, isNot(contains('newLocations')));
...@@ -2003,8 +2001,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2003,8 +2001,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag.
testWidgets('ext.flutter.inspector.show', (WidgetTester tester) async { testWidgets('ext.flutter.inspector.show', (WidgetTester tester) async {
final Iterable<Map<Object, Object>> extensionChangedEvents = service.getServiceExtensionStateChangedEvents('ext.flutter.inspector.show'); final Iterable<Map<Object, Object?>> extensionChangedEvents = service.getServiceExtensionStateChangedEvents('ext.flutter.inspector.show');
Map<Object, Object> extensionChangedEvent; Map<Object, Object?> extensionChangedEvent;
service.rebuildCount = 0; service.rebuildCount = 0;
expect(extensionChangedEvents, isEmpty); expect(extensionChangedEvents, isEmpty);
...@@ -2095,9 +2093,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2095,9 +2093,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Element repaintBoundary = final Element repaintBoundary =
find.byType(RepaintBoundaryWithDebugPaint).evaluate().single; 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); final int expectedChildLayerCount = getChildLayerCount(layer);
expect(expectedChildLayerCount, equals(2)); expect(expectedChildLayerCount, equals(2));
await expectLater( await expectLater(
...@@ -2123,8 +2121,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2123,8 +2121,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
matchesGoldenFile('inspector.repaint_boundary_margin_large.png'), matchesGoldenFile('inspector.repaint_boundary_margin_large.png'),
); );
final Layer layerParent = layer.parent; final Layer? layerParent = layer.parent;
final Layer firstChild = layer.firstChild; final Layer? firstChild = layer.firstChild;
expect(layerParent, isNotNull); expect(layerParent, isNotNull);
expect(firstChild, isNotNull); expect(firstChild, isNotNull);
...@@ -2212,7 +2210,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2212,7 +2210,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// Verify calling the screenshot method still works if the RenderObject // Verify calling the screenshot method still works if the RenderObject
// needs to be laid out again. // needs to be laid out again.
final RenderObject container = final RenderObject container =
find.byKey(outerContainerKey).evaluate().single.renderObject; find.byKey(outerContainerKey).evaluate().single.renderObject!;
container container
..markNeedsLayout() ..markNeedsLayout()
..markNeedsPaint(); ..markNeedsPaint();
...@@ -2264,7 +2262,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2264,7 +2262,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final Element clipRect = find.byType(ClipRRect).evaluate().single; final Element clipRect = find.byType(ClipRRect).evaluate().single;
final Future<ui.Image> clipRectScreenshot = service.screenshot( final Future<ui.Image?> clipRectScreenshot = service.screenshot(
clipRect, clipRect,
width: 100.0, width: 100.0,
height: 100.0, height: 100.0,
...@@ -2280,10 +2278,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2280,10 +2278,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// Verify we get the same image if we go through the service extension // Verify we get the same image if we go through the service extension
// instead of invoking the screenshot method directly. // instead of invoking the screenshot method directly.
final Future<Object> base64ScreenshotFuture = service.testExtension( final Future<Object?> base64ScreenshotFuture = service.testExtension(
'screenshot', 'screenshot',
<String, String>{ <String, String>{
'id': service.toId(clipRect, 'group'), 'id': service.toId(clipRect, 'group')!,
'width': '100.0', 'width': '100.0',
'height': '100.0', 'height': '100.0',
'margin': '20.0', 'margin': '20.0',
...@@ -2292,16 +2290,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2292,16 +2290,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
); );
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding; final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
final ui.Image screenshotImage = await binding.runAsync<ui.Image>(() async { final ui.Image screenshotImage = (await binding.runAsync<ui.Image>(() async {
final String base64Screenshot = await base64ScreenshotFuture as String; final String base64Screenshot = (await base64ScreenshotFuture)! as String;
final ui.Codec codec = await ui.instantiateImageCodec(base64.decode(base64Screenshot)); final ui.Codec codec = await ui.instantiateImageCodec(base64.decode(base64Screenshot));
final ui.FrameInfo frame = await codec.getNextFrame(); final ui.FrameInfo frame = await codec.getNextFrame();
return frame.image; return frame.image;
}, additionalTime: const Duration(seconds: 11)); }, additionalTime: const Duration(seconds: 11)))!;
await expectLater( await expectLater(
screenshotImage, screenshotImage,
matchesReferenceImage(await clipRectScreenshot), matchesReferenceImage((await clipRectScreenshot)!),
skip: !isLinux, skip: !isLinux,
); );
...@@ -2341,7 +2339,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2341,7 +2339,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
}); });
test('ext.flutter.inspector.structuredErrors', () async { test('ext.flutter.inspector.structuredErrors', () async {
List<Map<Object, Object>> flutterErrorEvents = service.getEventsDispatched('Flutter.Error'); List<Map<Object, Object?>> flutterErrorEvents = service.getEventsDispatched('Flutter.Error');
expect(flutterErrorEvents, isEmpty); expect(flutterErrorEvents, isEmpty);
final FlutterExceptionHandler oldHandler = FlutterError.presentError; final FlutterExceptionHandler oldHandler = FlutterError.presentError;
...@@ -2364,7 +2362,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2364,7 +2362,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(flutterErrorEvents, hasLength(1)); expect(flutterErrorEvents, hasLength(1));
// Validate the error contents. // Validate the error contents.
Map<Object, Object> error = flutterErrorEvents.first; Map<Object, Object?> error = flutterErrorEvents.first;
expect(error['description'], 'Exception caught by rendering library'); expect(error['description'], 'Exception caught by rendering library');
expect(error['children'], isEmpty); expect(error['children'], isEmpty);
...@@ -2390,7 +2388,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2390,7 +2388,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(error['renderedErrorText'], startsWith('Another exception was thrown:')); expect(error['renderedErrorText'], startsWith('Another exception was thrown:'));
// Reloads the app. // Reloads the app.
final FlutterExceptionHandler oldHandler = FlutterError.onError; final FlutterExceptionHandler? oldHandler = FlutterError.onError;
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding; final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
// We need the runTest to setup the fake async in the test binding. // We need the runTest to setup the fake async in the test binding.
await binding.runTest(() async { await binding.runTest(() async {
...@@ -2482,7 +2480,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -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)); expect(box.localToGlobal(Offset.zero), const Offset(123.0, 456.0));
await expectLater( await expectLater(
...@@ -2569,8 +2567,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2569,8 +2567,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
), ),
), ),
); );
final RenderBox box1 = key1.currentContext.findRenderObject() as RenderBox; final RenderBox box1 = key1.currentContext!.findRenderObject()! as RenderBox;
final RenderBox box2 = key2.currentContext.findRenderObject() as RenderBox; final RenderBox box2 = key2.currentContext!.findRenderObject()! as RenderBox;
// Snapshot the positions of the two relevant boxes to ensure that taking // Snapshot the positions of the two relevant boxes to ensure that taking
// screenshots doesn't impact their positions. // screenshots doesn't impact their positions.
final Offset position1 = box1.localToGlobal(Offset.zero); final Offset position1 = box1.localToGlobal(Offset.zero);
...@@ -2614,8 +2612,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2614,8 +2612,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// Make sure taking screenshots hasn't modified the positions of the // Make sure taking screenshots hasn't modified the positions of the
// TransformTarget or TransformFollower layers. // TransformTarget or TransformFollower layers.
expect(identical(key1.currentContext.findRenderObject(), box1), isTrue); expect(identical(key1.currentContext!.findRenderObject(), box1), isTrue);
expect(identical(key2.currentContext.findRenderObject(), box2), isTrue); expect(identical(key2.currentContext!.findRenderObject(), box2), isTrue);
expect(box1.localToGlobal(Offset.zero), equals(position1)); expect(box1.localToGlobal(Offset.zero), equals(position1));
expect(box2.localToGlobal(Offset.zero), equals(position2)); expect(box2.localToGlobal(Offset.zero), equals(position2));
}); });
...@@ -2639,13 +2637,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2639,13 +2637,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
); );
// Figure out the pubRootDirectory // Figure out the pubRootDirectory
final Map<String, Object> jsonObject = await service.testExtension( final Map<String, Object> jsonObject = (await service.testExtension(
'getSelectedWidget', 'getSelectedWidget',
<String, String>{'arg': null, 'objectGroup': 'my-group'}, <String, String>{'objectGroup': 'my-group'},
) as Map<String, Object>; ))! as Map<String, Object>;
final Map<String, Object> creationLocation = jsonObject['creationLocation'] as Map<String, Object>; final Map<String, Object> creationLocation = jsonObject['creationLocation']! as Map<String, Object>;
expect(creationLocation, isNotNull); expect(creationLocation, isNotNull);
final String file = creationLocation['file'] as String; final String file = creationLocation['file']! as String;
expect(file, endsWith('widget_inspector_test.dart')); expect(file, endsWith('widget_inspector_test.dart'));
final List<String> segments = Uri.parse(file).pathSegments; final List<String> segments = Uri.parse(file).pathSegments;
// Strip a couple subdirectories away to generate a plausible pub rootdirectory. // Strip a couple subdirectories away to generate a plausible pub rootdirectory.
...@@ -2657,7 +2655,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2657,7 +2655,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final List<dynamic> childrenOfMaterialApp = childrenOfRoot.first['children'] as List<dynamic>; final List<dynamic> childrenOfMaterialApp = childrenOfRoot.first['children'] as List<dynamic>;
final Map<String, Object> scaffold = childrenOfMaterialApp.first as Map<String, Object>; final Map<String, Object> scaffold = childrenOfMaterialApp.first as Map<String, Object>;
expect(scaffold['description'], 'Scaffold'); 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 String details = service.getDetailsSubtree(objectId, 'foo2');
final List<dynamic> detailedChildren = json.decode(details)['children'] as List<dynamic>; final List<dynamic> detailedChildren = json.decode(details)['children'] as List<dynamic>;
...@@ -2668,7 +2666,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2668,7 +2666,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
appBars.add(child); appBars.add(child);
} }
if (child.containsKey('children')) { if (child.containsKey('children')) {
visitChildren(child['children'] as List<dynamic>); visitChildren(child['children']! as List<dynamic>);
} }
} }
} }
...@@ -2708,10 +2706,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2708,10 +2706,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
addAdditionalPropertiesCallback: addAdditionalPropertiesCallback:
(DiagnosticsNode node, InspectorSerializationDelegate delegate) { (DiagnosticsNode node, InspectorSerializationDelegate delegate) {
final Map<String, Object> additionalJson = <String, Object>{}; final Map<String, Object> additionalJson = <String, Object>{};
final Object value = node.value; final Object? value = node.value;
if (value is Element) { if (value is Element) {
additionalJson['renderObject'] = additionalJson['renderObject'] =
value.renderObject.toDiagnosticsNode().toJsonMap( value.renderObject!.toDiagnosticsNode().toJsonMap(
delegate.copyWith(subtreeDepth: 0), delegate.copyWith(subtreeDepth: 0),
); );
} }
...@@ -2719,11 +2717,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2719,11 +2717,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
return additionalJson; return additionalJson;
}, },
); );
final Map<String, Object> json = node.toJsonMap(delegate); final Map<String, Object?> json = node.toJsonMap(delegate);
expect(json['callbackExecuted'], true); expect(json['callbackExecuted'], true);
expect(json.containsKey('renderObject'), true); expect(json.containsKey('renderObject'), true);
expect(json['renderObject'], isA<Map<String, dynamic>>()); expect(json['renderObject'], isA<Map<String, dynamic>>());
final Map<String, dynamic> renderObjectJson = json['renderObject'] as Map<String, dynamic>; final Map<String, dynamic> renderObjectJson = json['renderObject']! as Map<String, dynamic>;
expect(renderObjectJson['description'], startsWith('RenderFlex')); expect(renderObjectJson['description'], startsWith('RenderFlex'));
final InspectorSerializationDelegate emptyDelegate = final InspectorSerializationDelegate emptyDelegate =
...@@ -2760,7 +2758,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -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), isTrue);
expect(debugIsLocalCreationLocation(element.widget), isTrue); expect(debugIsLocalCreationLocation(element.widget), isTrue);
...@@ -2778,8 +2776,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ...@@ -2778,8 +2776,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
} }
void addToKnownLocationsMap({ void addToKnownLocationsMap({
@required Map<int, _CreationLocation> knownLocations, required Map<int, _CreationLocation> knownLocations,
@required Map<String, List<int>> newLocations, required Map<String, List<int>> newLocations,
}) { }) {
newLocations.forEach((String file, List<int> entries) { newLocations.forEach((String file, List<int> entries) {
assert(entries.length % 3 == 0); assert(entries.length % 3 == 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 '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