Unverified Commit e1512b4d authored by Albertus Angga Raharja's avatar Albertus Angga Raharja Committed by GitHub

Add additional properties callback in Inspector Serialization Delegate (#45531)

* Add additional properties callback in Inspector Serialization Delegate

* Rename _SerializationDelegate to InspectorSerializationDelegate and add test

* Fix indentation

* Remove trailing whitespace

* Handle case when addAdditionalPropertiesCallback returns null

* Improve docs and minor renames

* Improve docs

* Improve documentation
parent 0190e404
......@@ -2599,6 +2599,76 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
visitChildren(detailedChildren);
expect(appBars.single, isNot(contains('children')));
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // Test requires --track-widget-creation flag.
testWidgets('InspectorSerializationDelegate addAdditionalPropertiesCallback', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Hello World!',
home: Scaffold(
appBar: AppBar(
title: const Text('Hello World!'),
),
body: Center(
child: Column(
children: const <Widget>[
Text('Hello World!'),
],
),
),
),
)
);
final Finder columnWidgetFinder = find.byType(Column);
expect(columnWidgetFinder, findsOneWidget);
final Element columnWidgetElement = columnWidgetFinder
.evaluate()
.first;
final DiagnosticsNode node = columnWidgetElement.toDiagnosticsNode();
final InspectorSerializationDelegate delegate =
InspectorSerializationDelegate(
service: service,
summaryTree: false,
includeProperties: true,
addAdditionalPropertiesCallback:
(DiagnosticsNode node, InspectorSerializationDelegate delegate) {
final Map<String, Object> additionalJson = <String, Object>{};
final Object value = node.value;
if (value is Element) {
additionalJson['renderObject'] =
value.renderObject.toDiagnosticsNode().toJsonMap(
delegate.copyWith(subtreeDepth: 0),
);
}
additionalJson['callbackExecuted'] = true;
return additionalJson;
},
);
final Map<String, Object> json = node.toJsonMap(delegate);
expect(json['callbackExecuted'], true);
expect(json.containsKey('renderObject'), true);
expect(json['renderObject'], isA<Map<String, dynamic>>());
final Map<String, dynamic> renderObjectJson = json['renderObject'];
expect(renderObjectJson['description'], startsWith('RenderFlex'));
final InspectorSerializationDelegate emptyDelegate =
InspectorSerializationDelegate(
service: service,
summaryTree: false,
includeProperties: true,
addAdditionalPropertiesCallback:
(DiagnosticsNode node, InspectorSerializationDelegate delegate) {
return null;
},
);
final InspectorSerializationDelegate defaultDelegate =
InspectorSerializationDelegate(
service: service,
summaryTree: false,
includeProperties: true,
addAdditionalPropertiesCallback: null,
);
expect(node.toJsonMap(emptyDelegate), node.toJsonMap(defaultDelegate));
});
}
}
......
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