From 4356d3b676c42a9e6771c025226603d7d6d4ced9 Mon Sep 17 00:00:00 2001 From: Kenzie Davisson <43759233+kenzieschmoll@users.noreply.github.com> Date: Tue, 13 Sep 2022 09:53:24 -0700 Subject: [PATCH] Create an enum for widget inspector service extensions for use by tools (#111405) --- .../lib/src/widgets/service_extensions.dart | 366 +++++++++++++ .../lib/src/widgets/widget_inspector.dart | 53 +- .../test/widgets/widget_inspector_test.dart | 513 ++++++++++++------ 3 files changed, 744 insertions(+), 188 deletions(-) diff --git a/packages/flutter/lib/src/widgets/service_extensions.dart b/packages/flutter/lib/src/widgets/service_extensions.dart index 49c80f94fd..60a0097342 100644 --- a/packages/flutter/lib/src/widgets/service_extensions.dart +++ b/packages/flutter/lib/src/widgets/service_extensions.dart @@ -94,3 +94,369 @@ enum WidgetsServiceExtensions { /// registered. debugAllowBanner, } + +/// Service extension constants for the Widget Inspector. +/// +/// These constants will be used when registering service extensions in the +/// framework, and they will also be used by tools and services that call these +/// service extensions. +/// +/// The String value for each of these extension names should be accessed by +/// calling the `.name` property on the enum value. +enum WidgetInspectorServiceExtensions { + /// Name of service extension that, when called, will determine whether + /// [FlutterError] messages will be presented using a structured format. + /// + /// See also: + /// + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + /// * [WidgetInspectorService._reportStructuredError], which is the error + /// reporter that will be used when this service extension is enabled. + structuredErrors, + + /// Name of service extension that, when called, will change the value of + /// [WidgetsApp.debugShowWidgetInspectorOverride], which controls whether the + /// on-device widget inspector is visible. + /// + /// See also: + /// * [WidgetsApp.debugShowWidgetInspectorOverride], which is the flag that + /// this service extension exposes. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + show, + + /// Name of service extension that, when called, changes the value of + /// [WidgetInspectorService._trackRebuildDirtyWidgets], which determines + /// whether a callback is invoked for every dirty [Widget] built each frame. + /// + /// This service extension is only supported if + /// [WidgetInspectorService._widgetCreationTracked] is true. + /// + /// See also: + /// + /// * [debugOnRebuildDirtyWidget], which is the nullable callback that is + /// called for every dirty widget built per frame + /// * [WidgetInspectorService._onRebuildWidget], which is the callback we + /// assign to [debugOnRebuildDirtyWidget] when this service extension is set + /// to true. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + trackRebuildDirtyWidgets, + + /// Name of service extension that, when called, changes the value of + /// [WidgetInspectorService._trackRepaintWidgets], which determines whether + /// a callback is invoked for every [RenderObject] painted each frame. + /// + /// This service extension is only supported if + /// [WidgetInspectorService._widgetCreationTracked] is true. + /// + /// See also: + /// + /// * [debugOnProfilePaint], which is the nullable callback that is called for + /// every dirty widget built per frame + /// * [WidgetInspectorService._onPaint], which is the callback we + /// assign to [debugOnRebuildDirtyWidget] when this service extension is set + /// to true. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + trackRepaintWidgets, + + /// Name of service extension that, when called, will clear all + /// [WidgetInspectorService] object references in all groups. + /// + /// See also: + /// + /// * [WidgetInspectorService.disposeAllGroups], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + disposeAllGroups, + + /// Name of service extension that, when called, will clear all + /// [WidgetInspectorService] object references in a group. + /// + /// See also: + /// + /// * [WidgetInspectorService.disposeGroup], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + disposeGroup, + + /// Name of service extension that, when called, returns whether it is + /// appropriate to display the Widget tree in the inspector, which is only + /// true after the application has rendered its first frame. + /// + /// See also: + /// + /// * [WidgetInspectorService.isWidgetTreeReady], the method that this service + /// extension calls. + /// * [WidgetsBinding.debugDidSendFirstFrameEvent], which stores the + /// value of whether the first frame has been rendered. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + isWidgetTreeReady, + + /// Name of service extension that, when called, will remove the object with + /// the specified `id` from the specified object group. + /// + /// See also: + /// + /// * [WidgetInspectorService.disposeId], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + disposeId, + + /// Name of service extension that, when called, will set the list of + /// directories that should be considered part of the local project for the + /// Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.addPubRootDirectories], which should be used in + /// place of this method to add directories. + /// * [WidgetInspectorService.removePubRootDirectories], which should be used + /// in place of this method to remove directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + @Deprecated( + 'Use addPubRootDirectories instead. ' + 'This feature was deprecated after v3.1.0-9.0.pre.', + ) + setPubRootDirectories, + + /// Name of service extension that, when called, will add a list of + /// directories that should be considered part of the local project for the + /// Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.addPubRootDirectories], the method that this + /// service extension calls. + /// * [WidgetInspectorService.removePubRootDirectories], which should be used + /// to remove directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + addPubRootDirectories, + + /// Name of service extension that, when called, will remove a list of + /// directories that should no longer be considered part of the local project + /// for the Widget inspector summary tree. + /// + /// See also: + /// + /// * [WidgetInspectorService.removePubRootDirectories], the method that this + /// service extension calls. + /// * [WidgetInspectorService.addPubRootDirectories], which should be used + /// to add directories. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + removePubRootDirectories, + + /// Name of service extension that, when called, will set the + /// [WidgetInspector] selection to the object matching the specified id and + /// will return whether the selection was changed. + /// + /// See also: + /// + /// * [WidgetInspectorService.setSelectionById], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + setSelectionById, + + /// Name of service extension that, when called, will retrieve the chain of + /// [DiagnosticsNode] instances form the root of the tree to the [Element] or + /// [RenderObject] matching the specified id, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService._getParentChain], the method that this service + /// extension calls. + /// * [WidgetInspectorService.getParentChain], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getParentChain, + + /// Name of service extension that, when called, will return the properties + /// for the [DiagnosticsNode] object matching the specified id, passed as an + /// argument. + /// + /// See also: + /// + /// * [WidgetInspectorService._getProperties], the method that this service + /// extension calls. + /// * [WidgetInspectorService.getProperties], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getProperties, + + /// Name of service extension that, when called, will return the children + /// for the [DiagnosticsNode] object matching the specified id, passed as an + /// argument. + /// + /// See also: + /// + /// * [WidgetInspectorService._getChildren], the method that this service + /// extension calls. + /// * [WidgetInspectorService.getChildren], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getChildren, + + /// Name of service extension that, when called, will return the children + /// created by user code for the [DiagnosticsNode] object matching the + /// specified id, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService._getChildrenSummaryTree], the method that this + /// service extension calls. + /// * [WidgetInspectorService.getChildrenSummaryTree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getChildrenSummaryTree, + + /// Name of service extension that, when called, will return all children and + /// their properties for the [DiagnosticsNode] object matching the specified + /// id, passed as an argument. + /// + /// See also: + /// + /// * [WidgetInspectorService._getChildrenDetailsSubtree], the method that + /// this service extension calls. + /// * [WidgetInspectorService.getChildrenDetailsSubtree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getChildrenDetailsSubtree, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the root [Element]. + /// + /// See also: + /// + /// * [WidgetInspectorService._getRootWidget], the method that this service + /// extension calls. + /// * [WidgetInspectorService.getRootWidget], which returns a json encoded + /// String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getRootWidget, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the root [RenderObject]. + /// + /// See also: + /// + /// * [WidgetInspectorService._getRootRenderObject], the method that this + /// service extension calls. + /// * [WidgetInspectorService.getRootRenderObject], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getRootRenderObject, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the root [Element] of the summary tree, which + /// only includes [Element]s that were created by user code. + /// + /// See also: + /// + /// * [WidgetInspectorService._getRootWidgetSummaryTree], the method that this + /// service extension calls. + /// * [WidgetInspectorService.getRootWidgetSummaryTree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getRootWidgetSummaryTree, + + /// Name of service extension that, when called, will return the details + /// subtree, which includes properties, rooted at the [DiagnosticsNode] object + /// matching the specified id and the having a size matching the specified + /// subtree depth, both passed as arguments. + /// + /// See also: + /// + /// * [WidgetInspectorService.getDetailsSubtree], the method that this service + /// extension calls. + /// * [WidgetInspectorService.getDetailsSubtree], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getDetailsSubtree, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the currently selected [RenderObject]. + /// + /// See also: + /// + /// * [WidgetInspectorService._getSelectedRenderObject], the method that this + /// service extension calls. + /// * [WidgetInspectorService.getSelectedRenderObject], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getSelectedRenderObject, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the currently selected [Element]. + /// + /// See also: + /// + /// * [WidgetInspectorService._getSelectedWidget], the method that this + /// service extension calls. + /// * [WidgetInspectorService.getSelectedWidget], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getSelectedWidget, + + /// Name of service extension that, when called, will return the + /// [DiagnosticsNode] data for the currently selected [Element] in the summary + /// tree, which only includes [Element]s created in user code. + /// + /// If the selected [Element] does not exist in the summary tree, the first + /// ancestor in the summary tree for the currently selected [Element] will be + /// returned. + /// + /// See also: + /// + /// * [WidgetInspectorService._getSelectedSummaryWidget], the method that this + /// service extension calls. + /// * [WidgetInspectorService.getSelectedSummaryWidget], which returns a json + /// encoded String representation of this data. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + getSelectedSummaryWidget, + + /// Name of service extension that, when called, will return whether [Widget] + /// creation locations are available. + /// + /// See also: + /// + /// * [WidgetInspectorService.isWidgetCreationTracked], the method that this + /// service extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + isWidgetCreationTracked, + + /// Name of service extension that, when called, will return a base64 encoded + /// image of the [RenderObject] or [Element] matching the specified 'id`, + /// passed as an argument, and sized at the specified 'width' and 'height' + /// values, also passed as arguments. + /// + /// See also: + /// + /// * [WidgetInspectorService.screenshot], the method that this service + /// extension calls. + /// * [WidgetInspectorService.initServiceExtensions], where the service + /// extension is registered. + screenshot, +} diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index a4c0032997..7734bd273c 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -29,6 +29,7 @@ import 'binding.dart'; import 'debug.dart'; import 'framework.dart'; import 'gesture_detector.dart'; +import 'service_extensions.dart'; /// Signature for the builder callback used by /// [WidgetInspector.selectButtonBuilder]. @@ -1007,7 +1008,7 @@ mixin WidgetInspectorService { SchedulerBinding.instance.addPersistentFrameCallback(_onFrameStart); _registerBoolServiceExtension( - name: 'structuredErrors', + name: WidgetInspectorServiceExtensions.structuredErrors.name, getter: () async => FlutterError.presentError == _reportStructuredError, setter: (bool value) { FlutterError.presentError = value ? _reportStructuredError : defaultExceptionHandler; @@ -1016,7 +1017,7 @@ mixin WidgetInspectorService { ); _registerBoolServiceExtension( - name: 'show', + name: WidgetInspectorServiceExtensions.show.name, getter: () async => WidgetsApp.debugShowWidgetInspectorOverride, setter: (bool value) { if (WidgetsApp.debugShowWidgetInspectorOverride == value) { @@ -1031,7 +1032,7 @@ mixin WidgetInspectorService { // Service extensions that are only supported if widget creation locations // are tracked. _registerBoolServiceExtension( - name: 'trackRebuildDirtyWidgets', + name: WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, getter: () async => _trackRebuildDirtyWidgets, setter: (bool value) async { if (value == _trackRebuildDirtyWidgets) { @@ -1054,7 +1055,7 @@ mixin WidgetInspectorService { ); _registerBoolServiceExtension( - name: 'trackRepaintWidgets', + name: WidgetInspectorServiceExtensions.trackRepaintWidgets.name, getter: () async => _trackRepaintWidgets, setter: (bool value) async { if (value == _trackRepaintWidgets) { @@ -1081,92 +1082,92 @@ mixin WidgetInspectorService { } _registerSignalServiceExtension( - name: 'disposeAllGroups', + name: WidgetInspectorServiceExtensions.disposeAllGroups.name, callback: () async { disposeAllGroups(); return null; }, ); _registerObjectGroupServiceExtension( - name: 'disposeGroup', + name: WidgetInspectorServiceExtensions.disposeGroup.name, callback: (String name) async { disposeGroup(name); return null; }, ); _registerSignalServiceExtension( - name: 'isWidgetTreeReady', + name: WidgetInspectorServiceExtensions.isWidgetTreeReady.name, callback: isWidgetTreeReady, ); _registerServiceExtensionWithArg( - name: 'disposeId', + name: WidgetInspectorServiceExtensions.disposeId.name, callback: (String? objectId, String objectGroup) async { disposeId(objectId, objectGroup); return null; }, ); _registerServiceExtensionVarArgs( - name: 'setPubRootDirectories', + name: WidgetInspectorServiceExtensions.setPubRootDirectories.name, callback: (List args) async { setPubRootDirectories(args); return null; }, ); _registerServiceExtensionVarArgs( - name: 'addPubRootDirectories', + name: WidgetInspectorServiceExtensions.addPubRootDirectories.name, callback: (List args) async { addPubRootDirectories(args); return null; }, ); _registerServiceExtensionVarArgs( - name: 'removePubRootDirectories', + name: WidgetInspectorServiceExtensions.removePubRootDirectories.name, callback: (List args) async { removePubRootDirectories(args); return null; }, ); _registerServiceExtensionWithArg( - name: 'setSelectionById', + name: WidgetInspectorServiceExtensions.setSelectionById.name, callback: setSelectionById, ); _registerServiceExtensionWithArg( - name: 'getParentChain', + name: WidgetInspectorServiceExtensions.getParentChain.name, callback: _getParentChain, ); _registerServiceExtensionWithArg( - name: 'getProperties', + name: WidgetInspectorServiceExtensions.getProperties.name, callback: _getProperties, ); _registerServiceExtensionWithArg( - name: 'getChildren', + name: WidgetInspectorServiceExtensions.getChildren.name, callback: _getChildren, ); _registerServiceExtensionWithArg( - name: 'getChildrenSummaryTree', + name: WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, callback: _getChildrenSummaryTree, ); _registerServiceExtensionWithArg( - name: 'getChildrenDetailsSubtree', + name: WidgetInspectorServiceExtensions.getChildrenDetailsSubtree.name, callback: _getChildrenDetailsSubtree, ); _registerObjectGroupServiceExtension( - name: 'getRootWidget', + name: WidgetInspectorServiceExtensions.getRootWidget.name, callback: _getRootWidget, ); _registerObjectGroupServiceExtension( - name: 'getRootRenderObject', + name: WidgetInspectorServiceExtensions.getRootRenderObject.name, callback: _getRootRenderObject, ); _registerObjectGroupServiceExtension( - name: 'getRootWidgetSummaryTree', + name: WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, callback: _getRootWidgetSummaryTree, ); registerServiceExtension( - name: 'getDetailsSubtree', + name: WidgetInspectorServiceExtensions.getDetailsSubtree.name, callback: (Map parameters) async { assert(parameters.containsKey('objectGroup')); final String? subtreeDepth = parameters['subtreeDepth']; @@ -1180,24 +1181,24 @@ mixin WidgetInspectorService { }, ); _registerServiceExtensionWithArg( - name: 'getSelectedRenderObject', + name: WidgetInspectorServiceExtensions.getSelectedRenderObject.name, callback: _getSelectedRenderObject, ); _registerServiceExtensionWithArg( - name: 'getSelectedWidget', + name: WidgetInspectorServiceExtensions.getSelectedWidget.name, callback: _getSelectedWidget, ); _registerServiceExtensionWithArg( - name: 'getSelectedSummaryWidget', + name: WidgetInspectorServiceExtensions.getSelectedSummaryWidget.name, callback: _getSelectedSummaryWidget, ); _registerSignalServiceExtension( - name: 'isWidgetCreationTracked', + name: WidgetInspectorServiceExtensions.isWidgetCreationTracked.name, callback: isWidgetCreationTracked, ); registerServiceExtension( - name: 'screenshot', + name: WidgetInspectorServiceExtensions.screenshot.name, callback: (Map parameters) async { assert(parameters.containsKey('id')); assert(parameters.containsKey('width')); diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index 3f0219a539..87103b0062 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -1782,10 +1782,19 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String? aId = service.toId(a, group1); expect(service.toId(a, group2), equals(aId)); expect(service.toId(a, group3), equals(aId)); - await service.testExtension('disposeGroup', {'objectGroup': group1}); - await service.testExtension('disposeGroup', {'objectGroup': group2}); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeGroup.name, + {'objectGroup': group1}, + ); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeGroup.name, + {'objectGroup': group2}, + ); expect(service.toObject(aId), equals(a)); - await service.testExtension('disposeGroup', {'objectGroup': group3}); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeGroup.name, + {'objectGroup': group3}, + ); expect(() => service.toObject(aId), throwsFlutterError); }); @@ -1797,11 +1806,20 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String aId = service.toId(a, group1)!; final String bId = service.toId(b, group1)!; expect(service.toId(a, group2), equals(aId)); - await service.testExtension('disposeId', {'arg': bId, 'objectGroup': group1}); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeId.name, + {'arg': bId, 'objectGroup': group1}, + ); expect(() => service.toObject(bId), throwsFlutterError); - await service.testExtension('disposeId', {'arg': aId, 'objectGroup': group1}); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeId.name, + {'arg': aId, 'objectGroup': group1}, + ); expect(service.toObject(aId), equals(a)); - await service.testExtension('disposeId', {'arg': aId, 'objectGroup': group2}); + await service.testExtension( + WidgetInspectorServiceExtensions.disposeId.name, + {'arg': aId, 'objectGroup': group2}, + ); expect(() => service.toObject(aId), throwsFlutterError); }); @@ -1842,7 +1860,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(selectionChangedCount, equals(2)); expect(service.selection.current, equals(elementB.renderObject)); - await service.testExtension('setSelectionById', {'arg': service.toId(elementA, 'my-group')!, 'objectGroup': 'my-group'}); + await service.testExtension( + WidgetInspectorServiceExtensions.setSelectionById.name, + {'arg': service.toId(elementA, 'my-group')!, 'objectGroup': 'my-group'}, + ); expect(selectionChangedCount, equals(3)); expect(service.selection.currentElement, equals(elementA)); expect(service.selection.current, equals(elementA.renderObject)); @@ -1870,7 +1891,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementB = find.text('b').evaluate().first; final String bId = service.toId(elementB, group)!; - final Object? jsonList = await service.testExtension('getParentChain', {'arg': bId, 'objectGroup': group}); + final Object? jsonList = await service.testExtension( + WidgetInspectorServiceExtensions.getParentChain.name, + {'arg': bId, 'objectGroup': group}, + ); expect(jsonList, isList); final List chainElements = jsonList! as List; final List expectedChain = elementB.debugGetDiagnosticChain().reversed.toList(); @@ -1910,7 +1934,10 @@ 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( + WidgetInspectorServiceExtensions.getProperties.name, + {'arg': id, 'objectGroup': group}, + ))! as List; final List properties = diagnostic.getProperties(); expect(properties, isNotEmpty); expect(propertiesJson.length, equals(properties.length)); @@ -1938,7 +1965,10 @@ 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( + WidgetInspectorServiceExtensions.getChildren.name, + {'arg': id, 'objectGroup': group}, + ))! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(propertiesJson.length, equals(children.length)); @@ -1966,7 +1996,10 @@ 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( + WidgetInspectorServiceExtensions.getChildrenDetailsSubtree.name, + {'arg': id, 'objectGroup': group}, + ))! as List; final List children = diagnostic.getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); @@ -2002,7 +2035,10 @@ 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( + WidgetInspectorServiceExtensions.getDetailsSubtree.name, + {'arg': id, 'objectGroup': group}, + ))! as Map; expect(subtreeJson['objectId'], equals(id)); final List childrenJson = subtreeJson['children']! as List; final List children = diagnostic.getChildren(); @@ -2026,7 +2062,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { } final Map deepSubtreeJson = (await service.testExtension( - 'getDetailsSubtree', + WidgetInspectorServiceExtensions.getDetailsSubtree.name, {'arg': id, 'objectGroup': group, 'subtreeDepth': '3'}, ))! as Map; final List deepChildrenJson = deepSubtreeJson['children']! as List; @@ -2048,7 +2084,10 @@ 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( + WidgetInspectorServiceExtensions.getDetailsSubtree.name, + {'arg': id, 'objectGroup': group}, + ))! as Map; expect(subtreeJson['objectId'], equals(id)); expect(subtreeJson, contains('children')); final List propertiesJson = subtreeJson['properties']! as List; @@ -2092,10 +2131,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); service.resetPubRootDirectories(); service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + {'objectGroup': 'my-group'}, + ))! as Map; service.resetPubRootDirectories(); - Map rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; + Map rootJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, + {'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. @@ -2114,16 +2159,25 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // directory. final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; service.resetPubRootDirectories(); - await service.testExtension('addPubRootDirectories', {'arg0': pubRootTest}); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': pubRootTest}, + ); - rootJson = (await service.testExtension('getRootWidgetSummaryTree', {'objectGroup': group}))! as Map; + rootJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, + {'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; 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( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + {'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; @@ -2132,7 +2186,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { 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; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + {'arg': childJson['objectId']! as String, 'objectGroup': group}, + ))! as List; expect(alternateChildrenJson.length, equals(1)); expect(childrenJson.length, equals(1)); alternateChildJson = alternateChildrenJson[0]! as Map; @@ -2143,7 +2200,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { childrenJson = childJson['children']! as List; childrenJson = childJson['children']! as List; - alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + {'arg': childJson['objectId']! as String, 'objectGroup': group}, + ))! as List; expect(alternateChildrenJson.length, equals(3)); expect(childrenJson.length, equals(3)); alternateChildJson = alternateChildrenJson[2]! as Map; @@ -2151,7 +2211,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(childJson['description'], startsWith('Text')); expect(alternateChildJson['description'], startsWith('Text')); expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - alternateChildrenJson = (await service.testExtension('getChildrenSummaryTree', {'arg': childJson['objectId']! as String, 'objectGroup': group}))! as List; + alternateChildrenJson = (await service.testExtension( + WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, + {'arg': childJson['objectId']! as String, 'objectGroup': group}, + ))! as List; expect(alternateChildrenJson.length , equals(0)); // Tests are failing when this typo is fixed. expect(childJson['chidlren'], isNull); @@ -2181,11 +2244,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); service.resetPubRootDirectories(); service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + {'objectGroup': 'my-group'}, + ))! as Map; service.setSelection(richTextDiagnostic.value, 'my-group'); service.resetPubRootDirectories(); - Map? summarySelection = await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}) as Map?; + Map? summarySelection = await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedSummaryWidget.name, + {'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); @@ -2199,9 +2268,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // directory. final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; service.resetPubRootDirectories(); - await service.testExtension('addPubRootDirectories', {'arg0': pubRootTest}); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': pubRootTest}, + ); - summarySelection = (await service.testExtension('getSelectedSummaryWidget', {'objectGroup': group}))! as Map; + summarySelection = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedSummaryWidget.name, + {'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. @@ -2209,7 +2284,10 @@ 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( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + {'objectGroup': 'my-group'}, + ))! as Map; expect(service.toObject(regularSelection['valueId']! as String), richTextDiagnostic.value); }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. @@ -2232,7 +2310,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.disposeAllGroups(); service.resetPubRootDirectories(); service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map jsonA = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + {'objectGroup': 'my-group'}, + ))! as Map; final Map creationLocationA = jsonA['creationLocation']! as Map; expect(creationLocationA, isNotNull); final String fileA = creationLocationA['file']! as String; @@ -2240,7 +2321,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final int columnA = creationLocationA['column']! as int; service.setSelection(elementB, 'my-group'); - final Map jsonB = (await service.testExtension('getSelectedWidget', {'objectGroup': 'my-group'}))! as Map; + final Map jsonB = (await service.testExtension( + WidgetInspectorServiceExtensions.getSelectedWidget.name, + {'objectGroup': 'my-group'}, + ))! as Map; final Map creationLocationB = jsonB['creationLocation']! as Map; expect(creationLocationB, isNotNull); final String fileB = creationLocationB['file']! as String; @@ -2289,12 +2373,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': pubRootTest}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2322,12 +2406,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': '/invalid/$pubRootTest'}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2355,12 +2439,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': 'file://$pubRootTest'}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2388,12 +2472,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': '$pubRootTest/different'}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2420,14 +2504,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - await service.testExtension('addPubRootDirectories', { - 'arg0': '/unrelated/$pubRootTest', - 'arg1': 'file://$pubRootTest', - }); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '/unrelated/$pubRootTest', + 'arg1': 'file://$pubRootTest', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2484,12 +2571,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}'; service.resetPubRootDirectories(); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': pubRootFramework}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2497,7 +2584,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2505,13 +2592,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.resetPubRootDirectories(); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': pubRootFramework, 'arg1': pubRootTest}, ); service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2519,7 +2606,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(richText, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2565,12 +2652,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': pubRootTest, 'isolateId': '34'}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2596,13 +2683,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - await service.testExtension('addPubRootDirectories', { - 'arg0': '/invalid/$pubRootTest', - 'isolateId': '34' - }); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '/invalid/$pubRootTest', + 'isolateId': '34' + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2629,12 +2719,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, {'arg0': 'file://$pubRootTest', 'isolateId': '34'}, ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2660,13 +2750,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - await service.testExtension('addPubRootDirectories', { - 'arg0': '$pubRootTest/different', - 'isolateId': '34' - }); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '$pubRootTest/different', + 'isolateId': '34' + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2692,15 +2785,18 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - await service.testExtension('addPubRootDirectories', { - 'arg0': '/unrelated/$pubRootTest', - 'isolateId': '34', - 'arg1': 'file://$pubRootTest', - }); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '/unrelated/$pubRootTest', + 'isolateId': '34', + 'arg1': 'file://$pubRootTest', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2746,7 +2842,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, { 'arg0': pubRootTest, 'arg1': 'file://$pubRootTest', @@ -2756,14 +2852,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), ); await service.testExtension( - 'removePubRootDirectories', + WidgetInspectorServiceExtensions.removePubRootDirectories.name, { 'arg0': pubRootTest, }, @@ -2771,7 +2867,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2796,13 +2892,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0': '$pubRootTest/different', - 'arg1': '/unrelated/$pubRootTest', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '$pubRootTest/different', + 'arg1': '/unrelated/$pubRootTest', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), @@ -2827,12 +2926,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0':'file://$pubRootTest' - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0':'file://$pubRootTest'}, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2857,15 +2957,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0': pubRootTest, - }); - service.testExtension('addPubRootDirectories', { - 'arg0': '/invalid/$pubRootTest', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': pubRootTest}, + ); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': '/invalid/$pubRootTest'}, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2889,24 +2991,28 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0': pubRootTest, - 'arg1': '/invalid/$pubRootTest', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': pubRootTest, + 'arg1': '/invalid/$pubRootTest', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), ); - service.testExtension('removePubRootDirectories', { - 'arg0': '/invalid/$pubRootTest', - }); + service.testExtension( + WidgetInspectorServiceExtensions.removePubRootDirectories.name, + {'arg0': '/invalid/$pubRootTest'}, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2937,11 +3043,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { .evaluate() .first; service.setSelection(richText, 'my-group'); - service.testExtension('addPubRootDirectories', { 'arg0': pubRootTest }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { 'arg0': pubRootTest }, + ); final Map jsonObject = (await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ))! as Map; expect(jsonObject, isNot(contains('createdByLocalProject'))); @@ -2961,10 +3070,13 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final String pubRootFramework = '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}'; service.resetPubRootDirectories(); - service.testExtension('addPubRootDirectories', {'arg0': pubRootFramework}); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': pubRootFramework}, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2972,22 +3084,24 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), isNot(contains('createdByLocalProject')), ); service.resetPubRootDirectories(); - service - .testExtension('addPubRootDirectories', { - 'arg0': pubRootFramework, - 'arg1': pubRootTest - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': pubRootFramework, + 'arg1': pubRootTest, + }, + ); service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -2995,7 +3109,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(richText, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ), contains('createdByLocalProject'), @@ -3034,7 +3148,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; await service.testExtension( - 'addPubRootDirectories', + WidgetInspectorServiceExtensions.addPubRootDirectories.name, { 'arg0': pubRootTest, 'arg1': 'file://$pubRootTest', @@ -3045,14 +3159,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group', 'isolateId': '34',}, ), contains('createdByLocalProject'), ); await service.testExtension( - 'removePubRootDirectories', + WidgetInspectorServiceExtensions.removePubRootDirectories.name, { 'arg0': pubRootTest, 'isolateId': '34', @@ -3061,7 +3175,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(elementA, 'my-group'); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group', 'isolateId': '34',}, ), isNot(contains('createdByLocalProject')), @@ -3086,13 +3200,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0': '$pubRootTest/different', - 'arg1': '/unrelated/$pubRootTest', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '$pubRootTest/different', + 'arg1': '/unrelated/$pubRootTest', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group', 'isolateId': '34',}, ), isNot(contains('createdByLocalProject')), @@ -3117,13 +3234,16 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0':'file://$pubRootTest', - 'isolateId': '34', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0':'file://$pubRootTest', + 'isolateId': '34', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group', 'isolateId': '34',}, ), contains('createdByLocalProject'), @@ -3148,17 +3268,23 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0': pubRootTest, - 'isolateId': '34', - }); - service.testExtension('addPubRootDirectories', { - 'arg0': '/invalid/$pubRootTest', - 'isolateId': '34', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': pubRootTest, + 'isolateId': '34', + }, + ); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': '/invalid/$pubRootTest', + 'isolateId': '34', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group', 'isolateId': '34',}, ), contains('createdByLocalProject'), @@ -3182,27 +3308,39 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element elementA = find.text('a').evaluate().first; service.setSelection(elementA, 'my-group'); - service.testExtension('addPubRootDirectories', { - 'arg0': pubRootTest, - 'arg1': '/invalid/$pubRootTest', - 'isolateId': '34', - }); + service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + { + 'arg0': pubRootTest, + 'arg1': '/invalid/$pubRootTest', + 'isolateId': '34', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', - {'objectGroup': 'my-group', 'isolateId': '34',}, + WidgetInspectorServiceExtensions.getSelectedWidget.name, + { + 'objectGroup': 'my-group', + 'isolateId': '34', + }, ), contains('createdByLocalProject'), ); - service.testExtension('removePubRootDirectories', { - 'arg0': '/invalid/$pubRootTest', - 'isolateId': '34', - }); + service.testExtension( + WidgetInspectorServiceExtensions.removePubRootDirectories.name, + { + 'arg0': '/invalid/$pubRootTest', + 'isolateId': '34', + }, + ); expect( await service.testExtension( - 'getSelectedWidget', - {'objectGroup': 'my-group', 'isolateId': '34',}, + WidgetInspectorServiceExtensions.getSelectedWidget.name, + { + 'objectGroup': 'my-group', + 'isolateId': '34', + }, ), contains('createdByLocalProject'), ); @@ -3221,7 +3359,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(clockDemoElement, 'my-group'); final Map jsonObject = (await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ))! as Map; final Map creationLocation = jsonObject['creationLocation']! as Map; @@ -3233,7 +3371,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // directory. final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; service.resetPubRootDirectories(); - await service.testExtension('addPubRootDirectories', {'arg0': pubRootTest}); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': pubRootTest}, + ); final List> rebuildEvents = service.getEventsDispatched('Flutter.RebuiltWidgets'); @@ -3241,7 +3382,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(service.rebuildCount, equals(0)); expect( - await service.testBoolExtension('trackRebuildDirtyWidgets', {'enabled': 'true'}), + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + {'enabled': 'true'}, + ), equals('true'), ); expect(service.rebuildCount, equals(1)); @@ -3412,7 +3556,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Turn off rebuild counts. expect( - await service.testBoolExtension('trackRebuildDirtyWidgets', {'enabled': 'false'}), + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name, + {'enabled': 'false'}, + ), equals('false'), ); @@ -3431,7 +3578,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.setSelection(clockDemoElement, 'my-group'); final Map jsonObject = (await service.testExtension( - 'getSelectedWidget', + WidgetInspectorServiceExtensions.getSelectedWidget.name, {'objectGroup': 'my-group'}, ))! as Map; final Map creationLocation = @@ -3444,7 +3591,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // directory. final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; service.resetPubRootDirectories(); - await service.testExtension('addPubRootDirectories', {'arg0': pubRootTest}); + await service.testExtension( + WidgetInspectorServiceExtensions.addPubRootDirectories.name, + {'arg0': pubRootTest}, + ); final List> repaintEvents = service.getEventsDispatched('Flutter.RepaintWidgets'); @@ -3452,7 +3602,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(service.rebuildCount, equals(0)); expect( - await service.testBoolExtension('trackRepaintWidgets', {'enabled': 'true'}), + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRepaintWidgets.name, + {'enabled': 'true'}, + ), equals('true'), ); // Unlike trackRebuildDirtyWidgets, trackRepaintWidgets doesn't force a full @@ -3526,7 +3679,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Turn off rebuild counts. expect( - await service.testBoolExtension('trackRepaintWidgets', {'enabled': 'false'}), + await service.testBoolExtension( + WidgetInspectorServiceExtensions.trackRepaintWidgets.name, + {'enabled': 'false'}, + ), equals('false'), ); @@ -3542,27 +3698,57 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { service.rebuildCount = 0; expect(extensionChangedEvents, isEmpty); - expect(await service.testBoolExtension('show', {'enabled': 'true'}), equals('true')); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + {'enabled': 'true'}, + ), + equals('true'), + ); expect(extensionChangedEvents.length, equals(1)); extensionChangedEvent = extensionChangedEvents.last; expect(extensionChangedEvent['extension'], equals('ext.flutter.inspector.show')); expect(extensionChangedEvent['value'], isTrue); expect(service.rebuildCount, equals(1)); - expect(await service.testBoolExtension('show', {}), equals('true')); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + {}, + ), + equals('true'), + ); expect(WidgetsApp.debugShowWidgetInspectorOverride, isTrue); expect(extensionChangedEvents.length, equals(1)); - expect(await service.testBoolExtension('show', {'enabled': 'true'}), equals('true')); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + {'enabled': 'true'}, + ), + equals('true'), + ); expect(extensionChangedEvents.length, equals(2)); extensionChangedEvent = extensionChangedEvents.last; expect(extensionChangedEvent['extension'], equals('ext.flutter.inspector.show')); expect(extensionChangedEvent['value'], isTrue); expect(service.rebuildCount, equals(1)); - expect(await service.testBoolExtension('show', {'enabled': 'false'}), equals('false')); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + {'enabled': 'false'}, + ), + equals('false'), + ); expect(extensionChangedEvents.length, equals(3)); extensionChangedEvent = extensionChangedEvents.last; expect(extensionChangedEvent['extension'], equals('ext.flutter.inspector.show')); expect(extensionChangedEvent['value'], isFalse); - expect(await service.testBoolExtension('show', {}), equals('false')); + expect( + await service.testBoolExtension( + WidgetInspectorServiceExtensions.show.name, + {}, + ), + equals('false'), + ); expect(extensionChangedEvents.length, equals(3)); expect(service.rebuildCount, equals(2)); expect(WidgetsApp.debugShowWidgetInspectorOverride, isFalse); @@ -3815,7 +4001,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Verify we get the same image if we go through the service extension // instead of invoking the screenshot method directly. final Future base64ScreenshotFuture = service.testExtension( - 'screenshot', + WidgetInspectorServiceExtensions.screenshot.name, { 'id': service.toId(clipRect, 'group')!, 'width': '100.0', @@ -3882,7 +4068,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { try { // Enable structured errors. expect( - await service.testBoolExtension('structuredErrors', {'enabled': 'true'}), + await service.testBoolExtension( + WidgetInspectorServiceExtensions.structuredErrors.name, + {'enabled': 'true'}, + ), equals('true'), ); @@ -4175,8 +4364,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { // Figure out the pubRootDirectory final Map jsonObject = (await service.testExtension( - 'getSelectedWidget', - {'objectGroup': 'my-group'}, + WidgetInspectorServiceExtensions.getSelectedWidget.name, + {'objectGroup': 'my-group'}, ))! as Map; final Map creationLocation = jsonObject['creationLocation']! as Map; expect(creationLocation, isNotNull);