@@ -1255,6 +1255,11 @@ mixin WidgetInspectorService {
1255
1255
callback: _getRootWidgetSummaryTreeWithPreviews,
1256
1256
registerExtension: registerExtension,
1257
1257
);
1258
+ registerServiceExtension (
1259
+ name: WidgetInspectorServiceExtensions .getRootWidgetTree.name,
1260
+ callback: _getRootWidgetTree,
1261
+ registerExtension: registerExtension,
1262
+ );
1258
1263
registerServiceExtension (
1259
1264
name: WidgetInspectorServiceExtensions .getDetailsSubtree.name,
1260
1265
callback: (Map <String , String > parameters) async {
@@ -1951,42 +1956,93 @@ mixin WidgetInspectorService {
1951
1956
String groupName, {
1952
1957
Map <String , Object >? Function (DiagnosticsNode , InspectorSerializationDelegate )? addAdditionalPropertiesCallback,
1953
1958
}) {
1954
- return _nodeToJson (
1955
- WidgetsBinding .instance.rootElement? .toDiagnosticsNode (),
1956
- InspectorSerializationDelegate (
1957
- groupName: groupName,
1958
- subtreeDepth: 1000000 ,
1959
- summaryTree: true ,
1960
- service: this ,
1961
- addAdditionalPropertiesCallback: addAdditionalPropertiesCallback,
1962
- ),
1959
+ return _getRootWidgetTreeImpl (
1960
+ groupName: groupName,
1961
+ isSummaryTree: true ,
1962
+ withPreviews: false ,
1963
+ addAdditionalPropertiesCallback: addAdditionalPropertiesCallback,
1963
1964
);
1964
1965
}
1965
1966
1966
-
1967
1967
Future <Map <String , Object ?>> _getRootWidgetSummaryTreeWithPreviews (
1968
1968
Map <String , String > parameters,
1969
1969
) {
1970
1970
final String groupName = parameters['groupName' ]! ;
1971
- final Map <String , Object ?>? result = _getRootWidgetSummaryTree (
1972
- groupName,
1973
- addAdditionalPropertiesCallback: (DiagnosticsNode node, InspectorSerializationDelegate ? delegate) {
1974
- final Map <String , Object > additionalJson = < String , Object > {};
1975
- final Object ? value = node.value;
1976
- if (value is Element ) {
1977
- final RenderObject ? renderObject = value.renderObject;
1978
- if (renderObject is RenderParagraph ) {
1979
- additionalJson['textPreview' ] = renderObject.text.toPlainText ();
1980
- }
1981
- }
1982
- return additionalJson;
1983
- },
1971
+ final Map <String , Object ?>? result = _getRootWidgetTreeImpl (
1972
+ groupName: groupName,
1973
+ isSummaryTree: true ,
1974
+ withPreviews: true ,
1984
1975
);
1985
1976
return Future <Map <String , dynamic >>.value (< String , dynamic > {
1986
1977
'result' : result,
1987
1978
});
1988
1979
}
1989
1980
1981
+ Future <Map <String , Object ?>> _getRootWidgetTree (
1982
+ Map <String , String > parameters,
1983
+ ) {
1984
+ final String groupName = parameters['groupName' ]! ;
1985
+ final bool isSummaryTree = parameters['isSummaryTree' ] == 'true' ;
1986
+ final bool withPreviews = parameters['withPreviews' ] == 'true' ;
1987
+
1988
+ final Map <String , Object ?>? result = _getRootWidgetTreeImpl (
1989
+ groupName: groupName,
1990
+ isSummaryTree: isSummaryTree,
1991
+ withPreviews: withPreviews,
1992
+ );
1993
+
1994
+ return Future <Map <String , dynamic >>.value (< String , dynamic > {
1995
+ 'result' : result,
1996
+ });
1997
+ }
1998
+
1999
+ Map <String , Object ?>? _getRootWidgetTreeImpl ({
2000
+ required String groupName,
2001
+ required bool isSummaryTree,
2002
+ required bool withPreviews,
2003
+ Map <String , Object >? Function (
2004
+ DiagnosticsNode , InspectorSerializationDelegate )?
2005
+ addAdditionalPropertiesCallback,
2006
+ }) {
2007
+ final bool shouldAddAdditionalProperties =
2008
+ addAdditionalPropertiesCallback != null || withPreviews;
2009
+
2010
+ // Combine the given addAdditionalPropertiesCallback with logic to add text
2011
+ // previews as well (if withPreviews is true):
2012
+ Map <String , Object >? combinedAddAdditionalPropertiesCallback (
2013
+ DiagnosticsNode node,
2014
+ InspectorSerializationDelegate delegate,
2015
+ ) {
2016
+ final Map <String , Object > additionalPropertiesJson =
2017
+ addAdditionalPropertiesCallback? .call (node, delegate) ??
2018
+ < String , Object > {};
2019
+ if (! withPreviews) {
2020
+ return additionalPropertiesJson;
2021
+ }
2022
+ final Object ? value = node.value;
2023
+ if (value is Element ) {
2024
+ final RenderObject ? renderObject = value.renderObject;
2025
+ if (renderObject is RenderParagraph ) {
2026
+ additionalPropertiesJson['textPreview' ] =
2027
+ renderObject.text.toPlainText ();
2028
+ }
2029
+ }
2030
+ return additionalPropertiesJson;
2031
+ }
2032
+ return _nodeToJson (
2033
+ WidgetsBinding .instance.rootElement? .toDiagnosticsNode (),
2034
+ InspectorSerializationDelegate (
2035
+ groupName: groupName,
2036
+ subtreeDepth: 1000000 ,
2037
+ summaryTree: isSummaryTree,
2038
+ service: this ,
2039
+ addAdditionalPropertiesCallback: shouldAddAdditionalProperties
2040
+ ? combinedAddAdditionalPropertiesCallback
2041
+ : null ,
2042
+ ),
2043
+ );
2044
+ }
2045
+
1990
2046
/// Returns a JSON representation of the subtree rooted at the
1991
2047
/// [DiagnosticsNode] object that `diagnosticsNodeId` references providing
1992
2048
/// information needed for the details subtree view.
0 commit comments