Unverified Commit e5d7bab1 authored by Jacob Richman's avatar Jacob Richman Committed by GitHub

Fix null safety error in inspector service extensions taking a variable number of args. (#68661)

* Fix null safety error in inspector service extensions taking variable numbers of args.

Fixes https://github.com/flutter/flutter/issues/68627.
Also fix all inspector tests that do not rely on golden image functionality
so that they run with --enable-experiment=non-nullable. This verifies there
is test coverage to ensure there isn't a regression.

* Remove uses of dynamic.
parent bcac9d4f
...@@ -880,17 +880,18 @@ mixin WidgetInspectorService { ...@@ -880,17 +880,18 @@ mixin WidgetInspectorService {
registerServiceExtension( registerServiceExtension(
name: name, name: name,
callback: (Map<String, String> parameters) async { callback: (Map<String, String> parameters) async {
const String argPrefix = 'arg';
final List<String> args = <String>[]; final List<String> args = <String>[];
parameters.forEach((String name, String value) { int index = 0;
if (name.startsWith(argPrefix)) { while (true) {
final int index = int.parse(name.substring(argPrefix.length)); final String name = 'arg$index';
if (index >= args.length) { if (parameters.containsKey(name)) {
args.length = index + 1; args.add(parameters[name]!);
} else {
break;
} }
args[index] = value; index++;
} }
}); assert(index == parameters.length);
return <String, Object?>{'result': await callback(args)}; return <String, Object?>{'result': await callback(args)};
}, },
); );
......
...@@ -30,7 +30,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -30,7 +30,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
} }
List<Map<Object, Object?>> getEventsDispatched(String eventKind) { List<Map<Object, Object?>> getEventsDispatched(String eventKind) {
return eventsDispatched.putIfAbsent(eventKind, () => <Map<Object, Object>>[]); return eventsDispatched.putIfAbsent(eventKind, () => <Map<Object, Object?>>[]);
} }
Iterable<Map<Object, Object?>> getServiceExtensionStateChangedEvents(String extensionName) { Iterable<Map<Object, Object?>> getServiceExtensionStateChangedEvents(String extensionName) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment