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
dd4a8150
Unverified
Commit
dd4a8150
authored
Jun 16, 2023
by
Polina Cherkasova
Committed by
GitHub
Jun 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update getProperties to handle Diagnosticable as input. (#128897)
parent
e87b2021
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
16 deletions
+58
-16
widget_inspector.dart
packages/flutter/lib/src/widgets/widget_inspector.dart
+22
-14
widget_inspector_test.dart
packages/flutter/test/widgets/widget_inspector_test.dart
+36
-2
No files found.
packages/flutter/lib/src/widgets/widget_inspector.dart
View file @
dd4a8150
...
...
@@ -1722,9 +1722,12 @@ mixin WidgetInspectorService {
return
_safeJsonEncode
(
_getProperties
(
diagnosticsNodeId
,
groupName
));
}
List
<
Object
>
_getProperties
(
String
?
diagnosticsNodeId
,
String
groupName
)
{
final
DiagnosticsNode
?
node
=
toObject
(
diagnosticsNodeId
)
as
DiagnosticsNode
?;
return
_nodesToJson
(
node
==
null
?
const
<
DiagnosticsNode
>[]
:
node
.
getProperties
(),
InspectorSerializationDelegate
(
groupName:
groupName
,
service:
this
),
parent:
node
);
List
<
Object
>
_getProperties
(
String
?
diagnosticsOrDiagnosticableId
,
String
groupName
)
{
final
DiagnosticsNode
?
node
=
_idToDiagnosticsNode
(
diagnosticsOrDiagnosticableId
);
if
(
node
==
null
)
{
return
const
<
Object
>[];
}
return
_nodesToJson
(
node
.
getProperties
(),
InspectorSerializationDelegate
(
groupName:
groupName
,
service:
this
),
parent:
node
);
}
/// Returns a JSON representation of the children of the [DiagnosticsNode]
...
...
@@ -1757,26 +1760,31 @@ mixin WidgetInspectorService {
return
_safeJsonEncode
(
_getChildrenSummaryTree
(
diagnosticsNodeId
,
groupName
));
}
List
<
Object
>
_getChildrenSummaryTree
(
String
?
diagnosticsNodeId
,
String
groupName
)
{
final
Object
?
theObject
=
toObject
(
diagnosticsNodeId
);
final
InspectorSerializationDelegate
delegate
=
InspectorSerializationDelegate
(
groupName:
groupName
,
summaryTree:
true
,
service:
this
);
// TODO(polina-c): remove this, when DevTools stops sending DiagnosticsNode.
DiagnosticsNode
?
_idToDiagnosticsNode
(
String
?
diagnosticsOrDiagnosticableId
)
{
// TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to
// getChildrenSummaryTree and getProperties.
// https://github.com/flutter/devtools/issues/3951
final
Object
?
theObject
=
toObject
(
diagnosticsOrDiagnosticableId
);
if
(
theObject
is
DiagnosticsNode
)
{
return
_nodesToJson
(
_getChildrenFiltered
(
theObject
,
delegate
),
delegate
,
parent:
theObject
)
;
return
theObject
;
}
if
(
theObject
is
Diagnosticable
)
{
final
DiagnosticsNode
node
=
theObject
.
toDiagnosticsNode
();
return
_nodesToJson
(
_getChildrenFiltered
(
node
,
delegate
),
delegate
,
parent:
node
);
return
theObject
.
toDiagnosticsNode
();
}
if
(
theObject
==
null
)
{
return
null
;
}
throw
StateError
(
'Unexpected object type
${theObject.runtimeType}
.'
);
}
List
<
Object
>
_getChildrenSummaryTree
(
String
?
diagnosticsOrDiagnosticableId
,
String
groupName
)
{
final
DiagnosticsNode
?
node
=
_idToDiagnosticsNode
(
diagnosticsOrDiagnosticableId
);
if
(
node
==
null
)
{
return
<
Object
>[];
}
throw
StateError
(
'Unexpected object type
${theObject.runtimeType}
'
);
final
InspectorSerializationDelegate
delegate
=
InspectorSerializationDelegate
(
groupName:
groupName
,
summaryTree:
true
,
service:
this
);
return
_nodesToJson
(
_getChildrenFiltered
(
node
,
delegate
),
delegate
,
parent:
node
);
}
/// Returns a JSON representation of the children of the [DiagnosticsNode]
...
...
packages/flutter/test/widgets/widget_inspector_test.dart
View file @
dd4a8150
...
...
@@ -899,7 +899,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
}
});
test
(
'WidgetInspectorService getProperties'
,
()
{
test
(
'WidgetInspectorService getProperties
for
$DiagnosticsNode
'
,
()
{
final
DiagnosticsNode
diagnostic
=
const
Text
(
'a'
,
textDirection:
TextDirection
.
ltr
).
toDiagnosticsNode
();
const
String
group
=
'group'
;
service
.
disposeAllGroups
();
...
...
@@ -915,6 +915,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
}
});
test
(
'WidgetInspectorService getProperties for
$Diagnosticable
'
,
()
{
const
Diagnosticable
diagnosticable
=
Text
(
'a'
,
textDirection:
TextDirection
.
ltr
);
const
String
group
=
'group'
;
service
.
disposeAllGroups
();
final
String
id
=
service
.
toId
(
diagnosticable
,
group
)!;
final
List
<
Object
?>
propertiesJson
=
json
.
decode
(
service
.
getProperties
(
id
,
group
))
as
List
<
Object
?>;
final
List
<
DiagnosticsNode
>
properties
=
diagnosticable
.
toDiagnosticsNode
().
getProperties
();
expect
(
properties
,
isNotEmpty
);
expect
(
propertiesJson
.
length
,
equals
(
properties
.
length
));
for
(
int
i
=
0
;
i
<
propertiesJson
.
length
;
++
i
)
{
final
Map
<
String
,
Object
?>
propertyJson
=
propertiesJson
[
i
]!
as
Map
<
String
,
Object
?>;
expect
(
service
.
toObject
(
propertyJson
[
'valueId'
]
as
String
?),
equals
(
properties
[
i
].
value
));
expect
(
service
.
toObject
(
propertyJson
[
'objectId'
]!
as
String
),
isA
<
DiagnosticsNode
>());
}
});
testWidgets
(
'WidgetInspectorService getChildren'
,
(
WidgetTester
tester
)
async
{
const
String
group
=
'test-group'
;
...
...
@@ -2107,7 +2123,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
}
});
test
(
'ext.flutter.inspector.getProperties'
,
()
async
{
test
(
'ext.flutter.inspector.getProperties
for
$DiagnosticsNode
'
,
()
async
{
final
DiagnosticsNode
diagnostic
=
const
Text
(
'a'
,
textDirection:
TextDirection
.
ltr
).
toDiagnosticsNode
();
const
String
group
=
'group'
;
final
String
id
=
service
.
toId
(
diagnostic
,
group
)!;
...
...
@@ -2125,6 +2141,24 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
}
});
test
(
'ext.flutter.inspector.getProperties for
$Diagnosticable
'
,
()
async
{
const
Diagnosticable
diagnosticable
=
Text
(
'a'
,
textDirection:
TextDirection
.
ltr
);
const
String
group
=
'group'
;
final
String
id
=
service
.
toId
(
diagnosticable
,
group
)!;
final
List
<
Object
?>
propertiesJson
=
(
await
service
.
testExtension
(
WidgetInspectorServiceExtensions
.
getProperties
.
name
,
<
String
,
String
>{
'arg'
:
id
,
'objectGroup'
:
group
},
))!
as
List
<
Object
?>;
final
List
<
DiagnosticsNode
>
properties
=
diagnosticable
.
toDiagnosticsNode
().
getProperties
();
expect
(
properties
,
isNotEmpty
);
expect
(
propertiesJson
.
length
,
equals
(
properties
.
length
));
for
(
int
i
=
0
;
i
<
propertiesJson
.
length
;
++
i
)
{
final
Map
<
String
,
Object
?>
propertyJson
=
propertiesJson
[
i
]!
as
Map
<
String
,
Object
?>;
expect
(
service
.
toObject
(
propertyJson
[
'valueId'
]
as
String
?),
equals
(
properties
[
i
].
value
));
expect
(
service
.
toObject
(
propertyJson
[
'objectId'
]!
as
String
),
isA
<
DiagnosticsNode
>());
}
});
testWidgets
(
'ext.flutter.inspector.getChildren'
,
(
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