forked from firka/flutter
Create custom DiagnosticsNode type for DevTools deep links. (#74455)
* Create custom DiagnosticsNode type for DevTools deep links.
This commit is contained in:
@@ -1398,11 +1398,11 @@ mixin WidgetInspectorService {
|
||||
}
|
||||
|
||||
/// Returns a DevTools uri linking to a specific element on the inspector page.
|
||||
String? _devToolsInspectorUriForElement(Object? object) {
|
||||
String? _devToolsInspectorUriForElement(Element element) {
|
||||
if (activeDevToolsServerAddress != null && _serviceInfo != null) {
|
||||
final Uri? vmServiceUri = _serviceInfo!.serverUri;
|
||||
if (vmServiceUri != null) {
|
||||
final String? inspectorRef = toId(object, _consoleObjectGroup);
|
||||
final String? inspectorRef = toId(element, _consoleObjectGroup);
|
||||
if (inspectorRef != null) {
|
||||
return devToolsInspectorUri(vmServiceUri, inspectorRef);
|
||||
}
|
||||
@@ -2934,8 +2934,9 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) {
|
||||
final String? devToolsInspectorUri =
|
||||
WidgetInspectorService.instance._devToolsInspectorUriForElement(target);
|
||||
if (devToolsInspectorUri != null) {
|
||||
devToolsDiagnostic = DiagnosticsNode.message(
|
||||
devToolsDiagnostic = DevToolsDeepLinkProperty(
|
||||
'To inspect this widget in Flutter DevTools, visit: $devToolsInspectorUri',
|
||||
devToolsInspectorUri,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2958,6 +2959,27 @@ Iterable<DiagnosticsNode> _describeRelevantUserCode(Element element) {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
||||
/// Debugging message for DevTools deep links.
|
||||
///
|
||||
/// The [value] for this property is a string representation of the Flutter
|
||||
/// DevTools url.
|
||||
///
|
||||
/// Properties `description` and `url` must not be null.
|
||||
class DevToolsDeepLinkProperty extends DiagnosticsProperty<String> {
|
||||
/// Creates a diagnostics property that displays a deep link to Flutter DevTools.
|
||||
///
|
||||
/// The [value] of this property will return a map of data for the Flutter
|
||||
/// DevTools deep link, including the full `url`, the Flutter DevTools `screenId`,
|
||||
/// and the `objectId` in Flutter DevTools that this diagnostic references.
|
||||
///
|
||||
/// The `description` and `url` arguments must not be null.
|
||||
DevToolsDeepLinkProperty(String description, String url)
|
||||
: assert(description != null),
|
||||
assert(url != null),
|
||||
super('', url, description: description, level: DiagnosticLevel.info);
|
||||
}
|
||||
|
||||
/// Returns if an object is user created.
|
||||
///
|
||||
/// This always returns false if it is not called in debug mode.
|
||||
|
||||
@@ -2835,6 +2835,31 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
||||
equals('http://127.0.0.1:9100/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A55269%2F798ay5al_FM%3D%2F&inspectorRef=inspector-0'),
|
||||
);
|
||||
});
|
||||
|
||||
test('DevToolsDeepLinkProperty test', () {
|
||||
final DevToolsDeepLinkProperty node =
|
||||
DevToolsDeepLinkProperty(
|
||||
'description of the deep link',
|
||||
'the-deep-link',
|
||||
);
|
||||
expect(node.toString(), equals('description of the deep link'));
|
||||
expect(node.name, isEmpty);
|
||||
expect(node.value, equals('the-deep-link'));
|
||||
expect(
|
||||
node.toJsonMap(const DiagnosticsSerializationDelegate()),
|
||||
equals(<String, dynamic>{
|
||||
'description': 'description of the deep link',
|
||||
'type': 'DevToolsDeepLinkProperty',
|
||||
'name': '',
|
||||
'style': 'singleLine',
|
||||
'allowNameWrap': true,
|
||||
'missingIfNull': false,
|
||||
'propertyType': 'String',
|
||||
'defaultLevel': 'info',
|
||||
'value': 'the-deep-link',
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user