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
74eb9df2
Unverified
Commit
74eb9df2
authored
Mar 26, 2021
by
xubaolin
Committed by
GitHub
Mar 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if `MultiChildRenderObjectElement` has an associated RO (#78854)
parent
e007cad2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
0 deletions
+104
-0
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+29
-0
framework_test.dart
packages/flutter/test/widgets/framework_test.dart
+75
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
74eb9df2
...
...
@@ -6176,6 +6176,35 @@ class MultiChildRenderObjectElement extends RenderObjectElement {
super
.
forgetChild
(
child
);
}
bool
_debugCheckHasAssociatedRenderObject
(
Element
newChild
)
{
assert
(()
{
if
(
newChild
.
renderObject
==
null
)
{
FlutterError
.
reportError
(
FlutterErrorDetails
(
exception:
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
ErrorSummary
(
'The children of `MultiChildRenderObjectElement` must each has an associated render object.'
),
ErrorHint
(
'This typically means that the `
${newChild.widget}
` or its children
\n
'
'are not a subtype of `RenderObjectWidget`.'
),
newChild
.
describeElement
(
'The following element does not have an associated render object'
),
DiagnosticsDebugCreator
(
DebugCreator
(
newChild
)),
]),
),
);
}
return
true
;
}());
return
true
;
}
@override
Element
inflateWidget
(
Widget
newWidget
,
Object
?
newSlot
)
{
final
Element
newChild
=
super
.
inflateWidget
(
newWidget
,
newSlot
);
assert
(
_debugCheckHasAssociatedRenderObject
(
newChild
));
return
newChild
;
}
@override
void
mount
(
Element
?
parent
,
Object
?
newSlot
)
{
super
.
mount
(
parent
,
newSlot
);
...
...
packages/flutter/test/widgets/framework_test.dart
View file @
74eb9df2
...
...
@@ -1172,6 +1172,64 @@ void main() {
);
});
testWidgets
(
'Can not attach a non-RenderObjectElement to the MultiChildRenderObjectElement - mount'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Column
(
children:
<
Widget
>[
Container
(),
const
_EmptyWidget
(),
],
),
);
final
dynamic
exception
=
tester
.
takeException
();
expect
(
exception
,
isFlutterError
);
expect
(
exception
.
toString
(),
equalsIgnoringHashCodes
(
'The children of `MultiChildRenderObjectElement` must each has an associated render object.
\n
'
'This typically means that the `_EmptyWidget` or its children
\n
'
'are not a subtype of `RenderObjectWidget`.
\n
'
'The following element does not have an associated render object:
\n
'
' _EmptyWidget
\n
'
'debugCreator: _EmptyWidget ← Column ← [root]'
),
);
});
testWidgets
(
'Can not attach a non-RenderObjectElement to the MultiChildRenderObjectElement - update'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Column
(
children:
<
Widget
>[
Container
(),
],
),
);
await
tester
.
pumpWidget
(
Column
(
children:
<
Widget
>[
Container
(),
const
_EmptyWidget
(),
],
),
);
final
dynamic
exception
=
tester
.
takeException
();
expect
(
exception
,
isFlutterError
);
expect
(
exception
.
toString
(),
equalsIgnoringHashCodes
(
'The children of `MultiChildRenderObjectElement` must each has an associated render object.
\n
'
'This typically means that the `_EmptyWidget` or its children
\n
'
'are not a subtype of `RenderObjectWidget`.
\n
'
'The following element does not have an associated render object:
\n
'
' _EmptyWidget
\n
'
'debugCreator: _EmptyWidget ← Column ← [root]'
),
);
});
testWidgets
(
'Element diagnostics'
,
(
WidgetTester
tester
)
async
{
GlobalKey
key0
;
await
tester
.
pumpWidget
(
Column
(
...
...
@@ -1849,3 +1907,20 @@ class FakeLeafRenderObject extends RenderBox {
class
TestRenderObjectElement
extends
RenderObjectElement
{
TestRenderObjectElement
()
:
super
(
Table
());
}
class
_EmptyWidget
extends
Widget
{
const
_EmptyWidget
({
Key
?
key
})
:
super
(
key:
key
);
@override
Element
createElement
()
=>
_EmptyElement
(
this
);
}
class
_EmptyElement
extends
Element
{
_EmptyElement
(
_EmptyWidget
widget
)
:
super
(
widget
);
@override
bool
get
debugDoingBuild
=>
false
;
@override
void
performRebuild
()
{}
}
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