Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ed3d4630
Unverified
Commit
ed3d4630
authored
Jun 14, 2023
by
Polina Cherkasova
Committed by
GitHub
Jun 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update getChildrenSummaryTree to handle Diagnosticable as input. (#128833)
parent
d64332a0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
3 deletions
+130
-3
widget_inspector.dart
packages/flutter/lib/src/widgets/widget_inspector.dart
+18
-2
widget_inspector_test.dart
packages/flutter/test/widgets/widget_inspector_test.dart
+112
-1
No files found.
packages/flutter/lib/src/widgets/widget_inspector.dart
View file @
ed3d4630
...
...
@@ -1758,9 +1758,25 @@ mixin WidgetInspectorService {
}
List
<
Object
>
_getChildrenSummaryTree
(
String
?
diagnosticsNodeId
,
String
groupName
)
{
final
DiagnosticsNode
?
node
=
toObject
(
diagnosticsNodeId
)
as
DiagnosticsNode
?
;
final
Object
?
theObject
=
toObject
(
diagnosticsNodeId
)
;
final
InspectorSerializationDelegate
delegate
=
InspectorSerializationDelegate
(
groupName:
groupName
,
summaryTree:
true
,
service:
this
);
return
_nodesToJson
(
node
==
null
?
const
<
DiagnosticsNode
>[]
:
_getChildrenFiltered
(
node
,
delegate
),
delegate
,
parent:
node
);
// TODO(polina-c): remove this, when DevTools stops sending DiagnosticsNode.
// https://github.com/flutter/devtools/issues/3951
if
(
theObject
is
DiagnosticsNode
)
{
return
_nodesToJson
(
_getChildrenFiltered
(
theObject
,
delegate
),
delegate
,
parent:
theObject
);
}
if
(
theObject
is
Diagnosticable
)
{
final
DiagnosticsNode
node
=
theObject
.
toDiagnosticsNode
();
return
_nodesToJson
(
_getChildrenFiltered
(
node
,
delegate
),
delegate
,
parent:
node
);
}
if
(
theObject
==
null
)
{
return
<
Object
>[];
}
throw
StateError
(
'Unexpected object type
${theObject.runtimeType}
'
);
}
/// Returns a JSON representation of the children of the [DiagnosticsNode]
...
...
packages/flutter/test/widgets/widget_inspector_test.dart
View file @
ed3d4630
...
...
@@ -2288,7 +2288,9 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect
(
nestedRelatedProperty
,
isNot
(
contains
(
'children'
)));
});
testWidgets
(
'ext.flutter.inspector.getRootWidgetSummaryTree'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'ext.flutter.inspector.getRootWidgetSummaryTree on
$DiagnosticsNode
'
,
(
WidgetTester
tester
)
async
{
// TODO(polina-c): delete this test once getChildrenSummaryTree stops accepting DiagnosticsNode.
// https://github.com/flutter/devtools/issues/3951
const
String
group
=
'test-group'
;
await
tester
.
pumpWidget
(
...
...
@@ -2397,6 +2399,115 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect
(
childJson
[
'chidlren'
],
isNull
);
},
skip:
!
WidgetInspectorService
.
instance
.
isWidgetCreationTracked
());
// [intended] Test requires --track-widget-creation flag.
testWidgets
(
'ext.flutter.inspector.getRootWidgetSummaryTree on
$Diagnosticable
'
,
(
WidgetTester
tester
)
async
{
const
String
group
=
'test-group'
;
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
Text
(
'a'
,
textDirection:
TextDirection
.
ltr
),
Text
(
'b'
,
textDirection:
TextDirection
.
ltr
),
Text
(
'c'
,
textDirection:
TextDirection
.
ltr
),
],
),
),
);
final
Element
elementA
=
find
.
text
(
'a'
).
evaluate
().
first
;
service
.
disposeAllGroups
();
service
.
resetPubRootDirectories
();
service
.
setSelection
(
elementA
,
'my-group'
);
final
Map
<
String
,
dynamic
>
jsonA
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getSelectedWidget
.
name
,
<
String
,
String
>{
'objectGroup'
:
'my-group'
},
))!
as
Map
<
String
,
dynamic
>;
service
.
resetPubRootDirectories
();
Map
<
String
,
Object
?>
rootJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getRootWidgetSummaryTree
.
name
,
<
String
,
String
>{
'objectGroup'
:
group
},
))!
as
Map
<
String
,
Object
?>;
// 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.
final
Object
?
rootWidget
=
service
.
toObject
(
rootJson
[
'valueId'
]!
as
String
);
expect
(
rootWidget
,
equals
(
WidgetsBinding
.
instance
.
rootElement
));
List
<
Object
?>
childrenJson
=
rootJson
[
'children'
]!
as
List
<
Object
?>;
// There are no summary tree children.
expect
(
childrenJson
.
length
,
equals
(
0
));
final
Map
<
String
,
Object
?>
creationLocation
=
jsonA
[
'creationLocation'
]!
as
Map
<
String
,
Object
?>;
expect
(
creationLocation
,
isNotNull
);
final
String
testFile
=
creationLocation
[
'file'
]!
as
String
;
expect
(
testFile
,
endsWith
(
'widget_inspector_test.dart'
));
final
List
<
String
>
segments
=
Uri
.
parse
(
testFile
).
pathSegments
;
// Strip a couple subdirectories away to generate a plausible pub root
// directory.
final
String
pubRootTest
=
'/
${segments.take(segments.length - 2).join('/')}
'
;
service
.
resetPubRootDirectories
();
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
addPubRootDirectories
.
name
,
<
String
,
String
>{
'arg0'
:
pubRootTest
},
);
rootJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getRootWidgetSummaryTree
.
name
,
<
String
,
String
>{
'objectGroup'
:
group
},
))!
as
Map
<
String
,
Object
?>;
childrenJson
=
rootJson
[
'children'
]!
as
List
<
Object
?>;
// The tree of nodes returned contains all widgets created directly by the
// test.
childrenJson
=
rootJson
[
'children'
]!
as
List
<
Object
?>;
expect
(
childrenJson
.
length
,
equals
(
1
));
List
<
Object
?>
alternateChildrenJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getChildrenSummaryTree
.
name
,
<
String
,
String
>{
'arg'
:
rootJson
[
'valueId'
]!
as
String
,
'objectGroup'
:
group
},
))!
as
List
<
Object
?>;
expect
(
alternateChildrenJson
.
length
,
equals
(
1
));
Map
<
String
,
Object
?>
childJson
=
childrenJson
[
0
]!
as
Map
<
String
,
Object
?>;
Map
<
String
,
Object
?>
alternateChildJson
=
alternateChildrenJson
[
0
]!
as
Map
<
String
,
Object
?>;
expect
(
childJson
[
'description'
],
startsWith
(
'Directionality'
));
expect
(
alternateChildJson
[
'description'
],
startsWith
(
'Directionality'
));
expect
(
alternateChildJson
[
'valueId'
],
equals
(
childJson
[
'valueId'
]));
childrenJson
=
childJson
[
'children'
]!
as
List
<
Object
?>;
alternateChildrenJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getChildrenSummaryTree
.
name
,
<
String
,
String
>{
'arg'
:
childJson
[
'valueId'
]!
as
String
,
'objectGroup'
:
group
},
))!
as
List
<
Object
?>;
expect
(
alternateChildrenJson
.
length
,
equals
(
1
));
expect
(
childrenJson
.
length
,
equals
(
1
));
alternateChildJson
=
alternateChildrenJson
[
0
]!
as
Map
<
String
,
Object
?>;
childJson
=
childrenJson
[
0
]!
as
Map
<
String
,
Object
?>;
expect
(
childJson
[
'description'
],
startsWith
(
'Stack'
));
expect
(
alternateChildJson
[
'description'
],
startsWith
(
'Stack'
));
expect
(
alternateChildJson
[
'valueId'
],
equals
(
childJson
[
'valueId'
]));
childrenJson
=
childJson
[
'children'
]!
as
List
<
Object
?>;
childrenJson
=
childJson
[
'children'
]!
as
List
<
Object
?>;
alternateChildrenJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getChildrenSummaryTree
.
name
,
<
String
,
String
>{
'arg'
:
childJson
[
'valueId'
]!
as
String
,
'objectGroup'
:
group
},
))!
as
List
<
Object
?>;
expect
(
alternateChildrenJson
.
length
,
equals
(
3
));
expect
(
childrenJson
.
length
,
equals
(
3
));
alternateChildJson
=
alternateChildrenJson
[
2
]!
as
Map
<
String
,
Object
?>;
childJson
=
childrenJson
[
2
]!
as
Map
<
String
,
Object
?>;
expect
(
childJson
[
'description'
],
startsWith
(
'Text'
));
expect
(
alternateChildJson
[
'description'
],
startsWith
(
'Text'
));
expect
(
alternateChildJson
[
'valueId'
],
equals
(
childJson
[
'valueId'
]));
alternateChildrenJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getChildrenSummaryTree
.
name
,
<
String
,
String
>{
'arg'
:
childJson
[
'valueId'
]!
as
String
,
'objectGroup'
:
group
},
))!
as
List
<
Object
?>;
expect
(
alternateChildrenJson
.
length
,
equals
(
0
));
// Tests are failing when this typo is fixed.
expect
(
childJson
[
'chidlren'
],
isNull
);
},
skip:
!
WidgetInspectorService
.
instance
.
isWidgetCreationTracked
());
// [intended] Test requires --track-widget-creation flag.
testWidgets
(
'ext.flutter.inspector.getRootWidgetSummaryTreeWithPreviews'
,
(
WidgetTester
tester
)
async
{
const
String
group
=
'test-group'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment