diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index b7a96a50fa6..45a98005085 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -880,17 +880,18 @@ mixin WidgetInspectorService { registerServiceExtension( name: name, callback: (Map parameters) async { - const String argPrefix = 'arg'; final List args = []; - parameters.forEach((String name, String value) { - if (name.startsWith(argPrefix)) { - final int index = int.parse(name.substring(argPrefix.length)); - if (index >= args.length) { - args.length = index + 1; - } - args[index] = value; + int index = 0; + while (true) { + final String name = 'arg$index'; + if (parameters.containsKey(name)) { + args.add(parameters[name]!); + } else { + break; } - }); + index++; + } + assert(index == parameters.length); return {'result': await callback(args)}; }, ); diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index 4e4546e1046..0f43c6ebe26 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -780,7 +780,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String bId = service.toId(elementB, group)!; final Object? jsonList = json.decode(service.getParentChain(bId, group)); expect(jsonList, isList); - final List chainElements = jsonList! as List; + final List chainElements = jsonList! as List; final List expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); // Sanity check that the chain goes back to the root. expect(expectedChain.first, tester.binding.renderViewElement); @@ -788,15 +788,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(chainElements.length, equals(expectedChain.length)); for (int i = 0; i < expectedChain.length; i += 1) { expect(chainElements[i], isMap); - final Map chainNode = chainElements[i] as Map; + final Map chainNode = chainElements[i]! as Map; final Element element = expectedChain[i]; expect(chainNode['node'], isMap); - final Map jsonNode = chainNode['node']! as Map; + final Map jsonNode = chainNode['node']! as Map; expect(service.toObject(jsonNode['valueId']! as String), equals(element)); expect(service.toObject(jsonNode['objectId']! as String), isA()); expect(chainNode['children'], isList); - final List jsonChildren = chainNode['children']! as List; + final List jsonChildren = chainNode['children']! as List; final List childrenElements = []; element.visitChildren(childrenElements.add); expect(jsonChildren.length, equals(childrenElements.length)); @@ -807,7 +807,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { } for (int j = 0; j < childrenElements.length; j += 1) { expect(jsonChildren[j], isMap); - final Map childJson = jsonChildren[j] as Map; + final Map childJson = jsonChildren[j]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); expect(service.toObject(childJson['objectId']! as String), isA()); } @@ -819,12 +819,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { const String group = 'group'; service.disposeAllGroups(); final String id = service.toId(diagnostic, group)!; - final List propertiesJson = json.decode(service.getProperties(id, group)) as List; + final List propertiesJson = json.decode(service.getProperties(id, group)) as List; final List properties = diagnostic.getProperties(); expect(properties, isNotEmpty); expect(propertiesJson.length, equals(properties.length)); for (int i = 0; i < propertiesJson.length; ++i) { - final Map propertyJson = propertiesJson[i] as Map; + final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); expect(service.toObject(propertyJson['objectId']! as String), isA()); } @@ -848,12 +848,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); service.disposeAllGroups(); final String id = service.toId(diagnostic, group)!; - final List propertiesJson = json.decode(service.getChildren(id, group)) as List; + final List propertiesJson = json.decode(service.getChildren(id, group)) as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(propertiesJson.length, equals(children.length)); for (int i = 0; i < propertiesJson.length; ++i) { - final Map propertyJson = propertiesJson[i] as Map; + final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); expect(service.toObject(propertyJson['objectId']! as String), isA()); } @@ -878,22 +878,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); service.setPubRootDirectories([]); service.setSelection(elementA, 'my-group'); - final Map jsonA = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocationA = jsonA['creationLocation']! as Map; + final Map jsonA = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; + final Map creationLocationA = jsonA['creationLocation']! as Map; expect(creationLocationA, isNotNull); final String fileA = creationLocationA['file']! as String; final int lineA = creationLocationA['line']! as int; final int columnA = creationLocationA['column']! as int; - final List parameterLocationsA = creationLocationA['parameterLocations']! as List; + final List parameterLocationsA = creationLocationA['parameterLocations']! as List; service.setSelection(elementB, 'my-group'); - final Map jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocationB = jsonB['creationLocation']! as Map; + final Map jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; + final Map creationLocationB = jsonB['creationLocation']! as Map; expect(creationLocationB, isNotNull); final String fileB = creationLocationB['file']! as String; final int lineB = creationLocationB['line']! as int; final int columnB = creationLocationB['column']! as int; - final List parameterLocationsB = creationLocationB['parameterLocations']! as List; + final List parameterLocationsB = creationLocationB['parameterLocations']! as List; expect(fileA, endsWith('widget_inspector_test.dart')); expect(fileA, equals(fileB)); // We don't hardcode the actual lines the widgets are created on as that @@ -903,17 +903,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(columnA, equals(15)); expect(columnA, equals(columnB)); expect(parameterLocationsA.length, equals(1)); - final Map paramA = parameterLocationsA[0] as Map; + final Map paramA = parameterLocationsA[0]! as Map; expect(paramA['name'], equals('data')); expect(paramA['line'], equals(lineA)); expect(paramA['column'], equals(20)); expect(parameterLocationsB.length, equals(2)); - final Map paramB1 = parameterLocationsB[0] as Map; + final Map paramB1 = parameterLocationsB[0]! as Map; expect(paramB1['name'], equals('data')); expect(paramB1['line'], equals(lineB)); expect(paramB1['column'], equals(20)); - final Map paramB2 = parameterLocationsB[1] as Map; + final Map paramB2 = parameterLocationsB[1]! as Map; expect(paramB2['name'], equals('textDirection')); expect(paramB2['line'], equals(lineB)); expect(paramB2['column'], equals(25)); @@ -936,9 +936,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; late String pubRootTest; if (widgetTracked) { - final Map jsonObject = json.decode( - service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocation = jsonObject['creationLocation']! as Map; + final Map jsonObject = json.decode( + service.getSelectedWidget(null, 'my-group')) as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); @@ -998,9 +998,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; late String pubRootTest; if (widgetTracked) { - final Map jsonObject = json.decode( - service.getSelectedWidget(null, 'my-group')) as Map; - final Map creationLocation = jsonObject['creationLocation']! as Map; + final Map jsonObject = json.decode( + service.getSelectedWidget(null, 'my-group')) as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); @@ -1061,8 +1061,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); service.setPubRootDirectories([]); service.setSelection(elementA, 'my-group'); - Map jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; - Map creationLocation = jsonObject['creationLocation']! as Map; + Map jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; + Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); @@ -1099,9 +1099,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ).evaluate().first; service.setSelection(richText, 'my-group'); service.setPubRootDirectories([pubRootTest]); - jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; + jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; expect(jsonObject, isNot(contains('createdByLocalProject'))); - creationLocation = jsonObject['creationLocation']! as Map; + creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); // This RichText widget is created by the build method of the Text widget // thus the creation location is in text.dart not basic.dart @@ -1220,7 +1220,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String bId = service.toId(elementB, group)!; final Object? jsonList = await service.testExtension('getParentChain', {'arg': bId, 'objectGroup': group}); expect(jsonList, isList); - final List chainElements = jsonList! as List; + final List chainElements = jsonList! as List; final List expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); // Sanity check that the chain goes back to the root. expect(expectedChain.first, tester.binding.renderViewElement); @@ -1228,15 +1228,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(chainElements.length, equals(expectedChain.length)); for (int i = 0; i < expectedChain.length; i += 1) { expect(chainElements[i], isMap); - final Map chainNode = chainElements[i] as Map; + final Map chainNode = chainElements[i]! as Map; final Element element = expectedChain[i]; expect(chainNode['node'], isMap); - final Map jsonNode = chainNode['node']! as Map; + final Map jsonNode = chainNode['node']! as Map; expect(service.toObject(jsonNode['valueId']! as String), equals(element)); expect(service.toObject(jsonNode['objectId']! as String), isA()); expect(chainNode['children'], isList); - final List jsonChildren = chainNode['children']! as List; + final List jsonChildren = chainNode['children']! as List; final List childrenElements = []; element.visitChildren(childrenElements.add); expect(jsonChildren.length, equals(childrenElements.length)); @@ -1247,7 +1247,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { } for (int j = 0; j < childrenElements.length; j += 1) { expect(jsonChildren[j], isMap); - final Map childJson = jsonChildren[j] as Map; + final Map childJson = jsonChildren[j]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); expect(service.toObject(childJson['objectId']! as String), isA()); } @@ -1258,12 +1258,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); const String group = 'group'; final String id = service.toId(diagnostic, group)!; - final List propertiesJson = (await service.testExtension('getProperties', {'arg': id, 'objectGroup': group}))! as List; + final List propertiesJson = (await service.testExtension('getProperties', {'arg': id, 'objectGroup': group}))! as List; final List properties = diagnostic.getProperties(); expect(properties, isNotEmpty); expect(propertiesJson.length, equals(properties.length)); for (int i = 0; i < propertiesJson.length; ++i) { - final Map propertyJson = propertiesJson[i] as Map; + final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); expect(service.toObject(propertyJson['objectId']! as String), isA()); } @@ -1286,12 +1286,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final String id = service.toId(diagnostic, group)!; - final List propertiesJson = (await service.testExtension('getChildren', {'arg': id, 'objectGroup': group}))! as List; + final List propertiesJson = (await service.testExtension('getChildren', {'arg': id, 'objectGroup': group}))! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(propertiesJson.length, equals(children.length)); for (int i = 0; i < propertiesJson.length; ++i) { - final Map propertyJson = propertiesJson[i] as Map; + final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); expect(service.toObject(propertyJson['objectId']! as String), isA()); } @@ -1314,18 +1314,18 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final String id = service.toId(diagnostic, group)!; - final List childrenJson = (await service.testExtension('getChildrenDetailsSubtree', {'arg': id, 'objectGroup': group}))! as List; + final List childrenJson = (await service.testExtension('getChildrenDetailsSubtree', {'arg': id, 'objectGroup': group}))! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); for (int i = 0; i < childrenJson.length; ++i) { - final Map childJson = childrenJson[i] as Map; + final Map childJson = childrenJson[i]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); expect(service.toObject(childJson['objectId']! as String), isA()); - final List propertiesJson = childJson['properties']! as List; + final List propertiesJson = childJson['properties']! as List; final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode; final List expectedProperties = diagnosticsNode.getProperties(); - for (final Map propertyJson in propertiesJson.cast>()) { + for (final Map propertyJson in propertiesJson.cast>()) { final Object? property = service.toObject(propertyJson['objectId']! as String); expect(property, isA()); expect(expectedProperties, contains(property)); @@ -1350,37 +1350,37 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); final String id = service.toId(diagnostic, group)!; - final Map subtreeJson = (await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}))! as Map; + final Map subtreeJson = (await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}))! as Map; expect(subtreeJson['objectId'], equals(id)); - final List childrenJson = subtreeJson['children']! as List; + final List childrenJson = subtreeJson['children']! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); for (int i = 0; i < childrenJson.length; ++i) { - final Map childJson = childrenJson[i] as Map; + final Map childJson = childrenJson[i]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); expect(service.toObject(childJson['objectId']! as String), isA()); - final List propertiesJson = childJson['properties']! as List; - for (final Map propertyJson in propertiesJson.cast>()) { + final List propertiesJson = childJson['properties']! as List; + for (final Map propertyJson in propertiesJson.cast>()) { expect(propertyJson, isNot(contains('children'))); } final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode; final List expectedProperties = diagnosticsNode.getProperties(); - for (final Map propertyJson in propertiesJson.cast>()) { + for (final Map propertyJson in propertiesJson.cast>()) { final Object property = service.toObject(propertyJson['objectId']! as String)!; expect(property, isA()); expect(expectedProperties, contains(property)); } } - final Map deepSubtreeJson = (await service.testExtension( + final Map deepSubtreeJson = (await service.testExtension( 'getDetailsSubtree', {'arg': id, 'objectGroup': group, 'subtreeDepth': '3'}, - ))! as Map; - final List deepChildrenJson = deepSubtreeJson['children']! as List; - for (final Map childJson in deepChildrenJson.cast>()) { - final List propertiesJson = childJson['properties']! as List; - for (final Map propertyJson in propertiesJson.cast>()) { + ))! as Map; + final List deepChildrenJson = deepSubtreeJson['children']! as List; + for (final Map childJson in deepChildrenJson.cast>()) { + final List propertiesJson = childJson['properties']! as List; + for (final Map propertyJson in propertiesJson.cast>()) { expect(propertyJson, contains('children')); } } @@ -1396,20 +1396,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final DiagnosticsNode diagnostic = a.toDiagnosticsNode(); final String id = service.toId(diagnostic, group)!; - final Map subtreeJson = (await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}))! as Map; + final Map subtreeJson = (await service.testExtension('getDetailsSubtree', {'arg': id, 'objectGroup': group}))! as Map; expect(subtreeJson['objectId'], equals(id)); expect(subtreeJson, contains('children')); - final List propertiesJson = subtreeJson['properties']! as List; + final List propertiesJson = subtreeJson['properties']! as List; expect(propertiesJson.length, equals(1)); - final Map relatedProperty = propertiesJson.first as Map; + final Map relatedProperty = propertiesJson.first! as Map; expect(relatedProperty['name'], equals('related')); expect(relatedProperty['description'], equals('CyclicDiagnostic-b')); expect(relatedProperty, contains('isDiagnosticableValue')); expect(relatedProperty, isNot(contains('children'))); expect(relatedProperty, contains('properties')); - final List relatedWidgetProperties = relatedProperty['properties']! as List; + final List relatedWidgetProperties = relatedProperty['properties']! as List; expect(relatedWidgetProperties.length, equals(1)); - final Map nestedRelatedProperty = relatedWidgetProperties.first as Map; + final Map nestedRelatedProperty = relatedWidgetProperties.first! as Map; expect(nestedRelatedProperty['name'], equals('related')); // Make sure we do not include properties or children for diagnostic a // which we already included as the root node as that would indicate a @@ -1440,20 +1440,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; await service.testExtension('setPubRootDirectories', {}); - Map rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; + Map rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; // We haven't yet properly specified which directories are summary tree // directories so we get an empty tree other than the root that is always // included. final Object? rootWidget = service.toObject(rootJson['valueId']! as String); expect(rootWidget, equals(WidgetsBinding.instance?.renderViewElement)); - List childrenJson = rootJson['children']! as List; + List childrenJson = rootJson['children']! as List; // There are no summary tree children. expect(childrenJson.length, equals(0)); - final Map creationLocation = jsonA['creationLocation']! as Map; + final Map creationLocation = jsonA['creationLocation']! as Map; expect(creationLocation, isNotNull); final String testFile = creationLocation['file']! as String; expect(testFile, endsWith('widget_inspector_test.dart')); @@ -1463,42 +1463,42 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String pubRootTest = '/' + segments.take(segments.length - 2).join('/'); await service.testExtension('setPubRootDirectories', {'arg0': pubRootTest}); - rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; - childrenJson = rootJson['children']! as List; + rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; + childrenJson = rootJson['children']! as List; // The tree of nodes returned contains all widgets created directly by the // test. - childrenJson = rootJson['children']! as List; + childrenJson = rootJson['children']! as List; expect(childrenJson.length, equals(1)); - List alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': rootJson['objectId']! as String, 'objectGroup': group}))! as List; + List alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': rootJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length, equals(1)); - Map childJson = childrenJson[0] as Map; - Map alternateChildJson = alternateChildrenJson[0] as Map; + Map childJson = childrenJson[0]! as Map; + Map alternateChildJson = alternateChildrenJson[0]! as Map; expect(childJson['description'], startsWith('Directionality')); expect(alternateChildJson['description'], startsWith('Directionality')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - childrenJson = childJson['children']! as List; - alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; + childrenJson = childJson['children']! as List; + alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length, equals(1)); expect(childrenJson.length, equals(1)); - alternateChildJson = alternateChildrenJson[0] as Map; - childJson = childrenJson[0] as Map; + alternateChildJson = alternateChildrenJson[0]! as Map; + childJson = childrenJson[0]! as Map; expect(childJson['description'], startsWith('Stack')); expect(alternateChildJson['description'], startsWith('Stack')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - childrenJson = childJson['children']! as List; + childrenJson = childJson['children']! as List; - childrenJson = childJson['children']! as List; - alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; + childrenJson = childJson['children']! as List; + alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length, equals(3)); expect(childrenJson.length, equals(3)); - alternateChildJson = alternateChildrenJson[2] as Map; - childJson = childrenJson[2] as Map; + alternateChildJson = alternateChildrenJson[2]! as Map; + childJson = childrenJson[2]! as Map; expect(childJson['description'], startsWith('Text')); expect(alternateChildJson['description'], startsWith('Text')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; + alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; expect(alternateChildrenJson.length , equals(0)); expect(childJson['chidlren'], isNull); }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. @@ -1527,16 +1527,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; service.setSelection(richTextDiagnostic.value, 'my-group'); await service.testExtension('setPubRootDirectories', {}); - Map? summarySelection = await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}) as Map?; + Map? summarySelection = await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}) as Map?; // No summary selection because we haven't set the pub root directories // yet to indicate what directories are in the summary tree. expect(summarySelection, isNull); - final Map creationLocation = jsonA['creationLocation']! as Map; + final Map creationLocation = jsonA['creationLocation']! as Map; expect(creationLocation, isNotNull); final String testFile = creationLocation['file']! as String; expect(testFile, endsWith('widget_inspector_test.dart')); @@ -1546,7 +1546,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String pubRootTest = '/' + segments.take(segments.length - 2).join('/'); await service.testExtension('setPubRootDirectories', {'arg0': pubRootTest}); - summarySelection = (await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}))! as Map; + summarySelection = (await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}))! as Map; expect(summarySelection['valueId'], isNotNull); // We got the Text element instead of the selected RichText element // because only the RichText element is part of the summary tree. @@ -1554,7 +1554,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Verify tha the regular getSelectedWidget method still returns // the RichText object not the Text element. - final Map regularSelection = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map regularSelection = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; expect(service.toObject(regularSelection['valueId']! as String), richTextDiagnostic.value); }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag. @@ -1577,22 +1577,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; - final Map creationLocationA = jsonA['creationLocation']! as Map; + final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map creationLocationA = jsonA['creationLocation']! as Map; expect(creationLocationA, isNotNull); final String fileA = creationLocationA['file']! as String; final int lineA = creationLocationA['line']! as int; final int columnA = creationLocationA['column']! as int; - final List parameterLocationsA = creationLocationA['parameterLocations']! as List; + final List parameterLocationsA = creationLocationA['parameterLocations']! as List; service.setSelection(elementB, 'my-group'); - final Map jsonB = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; - final Map creationLocationB = jsonB['creationLocation']! as Map; + final Map jsonB = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map creationLocationB = jsonB['creationLocation']! as Map; expect(creationLocationB, isNotNull); final String fileB = creationLocationB['file']! as String; final int lineB = creationLocationB['line']! as int; final int columnB = creationLocationB['column']! as int; - final List parameterLocationsB = creationLocationB['parameterLocations']! as List; + final List parameterLocationsB = creationLocationB['parameterLocations']! as List; expect(fileA, endsWith('widget_inspector_test.dart')); expect(fileA, equals(fileB)); // We don't hardcode the actual lines the widgets are created on as that @@ -1602,17 +1602,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(columnA, equals(15)); expect(columnA, equals(columnB)); expect(parameterLocationsA.length, equals(1)); - final Map paramA = parameterLocationsA[0] as Map; + final Map paramA = parameterLocationsA[0]! as Map; expect(paramA['name'], equals('data')); expect(paramA['line'], equals(lineA)); expect(paramA['column'], equals(20)); expect(parameterLocationsB.length, equals(2)); - final Map paramB1 = parameterLocationsB[0] as Map; + final Map paramB1 = parameterLocationsB[0]! as Map; expect(paramB1['name'], equals('data')); expect(paramB1['line'], equals(lineB)); expect(paramB1['column'], equals(20)); - final Map paramB2 = parameterLocationsB[1] as Map; + final Map paramB2 = parameterLocationsB[1]! as Map; expect(paramB2['name'], equals('textDirection')); expect(paramB2['line'], equals(lineB)); expect(paramB2['column'], equals(25)); @@ -1635,8 +1635,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await service.testExtension('setPubRootDirectories', {}); service.setSelection(elementA, 'my-group'); - Map jsonObject = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; - Map creationLocation = jsonObject['creationLocation']! as Map; + Map jsonObject = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String fileA = creationLocation['file']! as String; expect(fileA, endsWith('widget_inspector_test.dart')); @@ -1674,9 +1674,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ).evaluate().first; service.setSelection(richText, 'my-group'); service.setPubRootDirectories([pubRootTest]); - jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; + jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map; expect(jsonObject, isNot(contains('createdByLocalProject'))); - creationLocation = jsonObject['creationLocation']! as Map; + creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); // This RichText widget is created by the build method of the Text widget // thus the creation location is in text.dart not basic.dart @@ -1705,11 +1705,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; service.setSelection(clockDemoElement, 'my-group'); - final Map jsonObject = (await service.testExtension( + final Map jsonObject = (await service.testExtension( 'getSelectedWidget', {'objectGroup': 'my-group'}, - ))! as Map; - final Map creationLocation = jsonObject['creationLocation']! as Map; + ))! as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String file = creationLocation['file']! as String; expect(file, endsWith('widget_inspector_test.dart')); @@ -1901,11 +1901,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; service.setSelection(clockDemoElement, 'my-group'); - final Map jsonObject = (await service.testExtension( + final Map jsonObject = (await service.testExtension( 'getSelectedWidget', - {'objectGroup': 'my-group'}))! as Map; - final Map creationLocation = - jsonObject['creationLocation']! as Map; + {'objectGroup': 'my-group'}))! as Map; + final Map creationLocation = + jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String file = creationLocation['file']! as String; expect(file, endsWith('widget_inspector_test.dart')); @@ -2637,11 +2637,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ); // Figure out the pubRootDirectory - final Map jsonObject = (await service.testExtension( + final Map jsonObject = (await service.testExtension( 'getSelectedWidget', {'objectGroup': 'my-group'}, - ))! as Map; - final Map creationLocation = jsonObject['creationLocation']! as Map; + ))! as Map; + final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull); final String file = creationLocation['file']! as String; expect(file, endsWith('widget_inspector_test.dart')); @@ -2651,22 +2651,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setPubRootDirectories([pubRootTest]); final String summary = service.getRootWidgetSummaryTree('foo1'); - final List childrenOfRoot = json.decode(summary)['children'] as List; - final List childrenOfMaterialApp = childrenOfRoot.first['children'] as List; - final Map scaffold = childrenOfMaterialApp.first as Map; + final List childrenOfRoot = json.decode(summary)['children'] as List; + final List childrenOfMaterialApp = (childrenOfRoot.first! as Map)['children']! as List; + final Map scaffold = childrenOfMaterialApp.first! as Map; expect(scaffold['description'], 'Scaffold'); final String objectId = scaffold['objectId']! as String; final String details = service.getDetailsSubtree(objectId, 'foo2'); - final List detailedChildren = json.decode(details)['children'] as List; + final List detailedChildren = json.decode(details)['children'] as List; - final List> appBars = >[]; - void visitChildren(List children) { - for (final Map child in children.cast>()) { + final List> appBars = >[]; + void visitChildren(List children) { + for (final Map child in children.cast>()) { if (child['description'] == 'AppBar') { appBars.add(child); } if (child.containsKey('children')) { - visitChildren(child['children']! as List); + visitChildren(child['children']! as List); } } } @@ -2720,8 +2720,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Map json = node.toJsonMap(delegate); expect(json['callbackExecuted'], true); expect(json.containsKey('renderObject'), true); - expect(json['renderObject'], isA>()); - final Map renderObjectJson = json['renderObject']! as Map; + expect(json['renderObject'], isA>()); + final Map renderObjectJson = json['renderObject']! as Map; expect(renderObjectJson['description'], startsWith('RenderFlex')); final InspectorSerializationDelegate emptyDelegate = diff --git a/packages/flutter/test/widgets/widget_inspector_test_utils.dart b/packages/flutter/test/widgets/widget_inspector_test_utils.dart index be12aed1b99..5ec33fd7694 100644 --- a/packages/flutter/test/widgets/widget_inspector_test_utils.dart +++ b/packages/flutter/test/widgets/widget_inspector_test_utils.dart @@ -30,7 +30,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { } List> getEventsDispatched(String eventKind) { - return eventsDispatched.putIfAbsent(eventKind, () => >[]); + return eventsDispatched.putIfAbsent(eventKind, () => >[]); } Iterable> getServiceExtensionStateChangedEvents(String extensionName) {