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
539f09f8
Unverified
Commit
539f09f8
authored
Jul 11, 2019
by
LongCatIsLooong
Committed by
GitHub
Jul 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `_debugWillReattachChildren` assertions from `_TableElement` (#34202)
parent
b1a86370
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
19 deletions
+46
-19
table.dart
packages/flutter/lib/src/widgets/table.dart
+1
-19
table_test.dart
packages/flutter/test/widgets/table_test.dart
+45
-0
No files found.
packages/flutter/lib/src/widgets/table.dart
View file @
539f09f8
...
@@ -250,13 +250,9 @@ class _TableElement extends RenderObjectElement {
...
@@ -250,13 +250,9 @@ class _TableElement extends RenderObjectElement {
List
<
_TableElementRow
>
_children
=
const
<
_TableElementRow
>[];
List
<
_TableElementRow
>
_children
=
const
<
_TableElementRow
>[];
bool
_debugWillReattachChildren
=
false
;
@override
@override
void
mount
(
Element
parent
,
dynamic
newSlot
)
{
void
mount
(
Element
parent
,
dynamic
newSlot
)
{
super
.
mount
(
parent
,
newSlot
);
super
.
mount
(
parent
,
newSlot
);
assert
(!
_debugWillReattachChildren
);
assert
(()
{
_debugWillReattachChildren
=
true
;
return
true
;
}());
_children
=
widget
.
children
.
map
<
_TableElementRow
>((
TableRow
row
)
{
_children
=
widget
.
children
.
map
<
_TableElementRow
>((
TableRow
row
)
{
return
_TableElementRow
(
return
_TableElementRow
(
key:
row
.
key
,
key:
row
.
key
,
...
@@ -266,32 +262,20 @@ class _TableElement extends RenderObjectElement {
...
@@ -266,32 +262,20 @@ class _TableElement extends RenderObjectElement {
}).
toList
(
growable:
false
),
}).
toList
(
growable:
false
),
);
);
}).
toList
(
growable:
false
);
}).
toList
(
growable:
false
);
assert
(()
{
_debugWillReattachChildren
=
false
;
return
true
;
}());
_updateRenderObjectChildren
();
_updateRenderObjectChildren
();
}
}
@override
@override
void
insertChildRenderObject
(
RenderObject
child
,
Element
slot
)
{
void
insertChildRenderObject
(
RenderObject
child
,
Element
slot
)
{
assert
(
_debugWillReattachChildren
);
renderObject
.
setupParentData
(
child
);
renderObject
.
setupParentData
(
child
);
}
}
@override
@override
void
moveChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
void
moveChildRenderObject
(
RenderObject
child
,
dynamic
slot
)
{
assert
(
_debugWillReattachChildren
);
}
}
@override
@override
void
removeChildRenderObject
(
RenderObject
child
)
{
void
removeChildRenderObject
(
RenderObject
child
)
{
assert
(()
{
if
(
_debugWillReattachChildren
)
return
true
;
for
(
Element
forgottenChild
in
_forgottenChildren
)
{
if
(
forgottenChild
.
renderObject
==
child
)
return
true
;
}
return
false
;
}());
final
TableCellParentData
childParentData
=
child
.
parentData
;
final
TableCellParentData
childParentData
=
child
.
parentData
;
renderObject
.
setChild
(
childParentData
.
x
,
childParentData
.
y
,
null
);
renderObject
.
setChild
(
childParentData
.
x
,
childParentData
.
y
,
null
);
}
}
...
@@ -300,8 +284,6 @@ class _TableElement extends RenderObjectElement {
...
@@ -300,8 +284,6 @@ class _TableElement extends RenderObjectElement {
@override
@override
void
update
(
Table
newWidget
)
{
void
update
(
Table
newWidget
)
{
assert
(!
_debugWillReattachChildren
);
assert
(()
{
_debugWillReattachChildren
=
true
;
return
true
;
}());
final
Map
<
LocalKey
,
List
<
Element
>>
oldKeyedRows
=
<
LocalKey
,
List
<
Element
>>{};
final
Map
<
LocalKey
,
List
<
Element
>>
oldKeyedRows
=
<
LocalKey
,
List
<
Element
>>{};
for
(
_TableElementRow
row
in
_children
)
{
for
(
_TableElementRow
row
in
_children
)
{
if
(
row
.
key
!=
null
)
{
if
(
row
.
key
!=
null
)
{
...
@@ -330,7 +312,7 @@ class _TableElement extends RenderObjectElement {
...
@@ -330,7 +312,7 @@ class _TableElement extends RenderObjectElement {
updateChildren
(
oldUnkeyedRows
.
current
.
children
,
const
<
Widget
>[],
forgottenChildren:
_forgottenChildren
);
updateChildren
(
oldUnkeyedRows
.
current
.
children
,
const
<
Widget
>[],
forgottenChildren:
_forgottenChildren
);
for
(
List
<
Element
>
oldChildren
in
oldKeyedRows
.
values
.
where
((
List
<
Element
>
list
)
=>
!
taken
.
contains
(
list
)))
for
(
List
<
Element
>
oldChildren
in
oldKeyedRows
.
values
.
where
((
List
<
Element
>
list
)
=>
!
taken
.
contains
(
list
)))
updateChildren
(
oldChildren
,
const
<
Widget
>[],
forgottenChildren:
_forgottenChildren
);
updateChildren
(
oldChildren
,
const
<
Widget
>[],
forgottenChildren:
_forgottenChildren
);
assert
(()
{
_debugWillReattachChildren
=
false
;
return
true
;
}());
_children
=
newChildren
;
_children
=
newChildren
;
_updateRenderObjectChildren
();
_updateRenderObjectChildren
();
_forgottenChildren
.
clear
();
_forgottenChildren
.
clear
();
...
...
packages/flutter/test/widgets/table_test.dart
View file @
539f09f8
...
@@ -19,6 +19,24 @@ class TestStatefulWidgetState extends State<TestStatefulWidget> {
...
@@ -19,6 +19,24 @@ class TestStatefulWidgetState extends State<TestStatefulWidget> {
Widget
build
(
BuildContext
context
)
=>
Container
();
Widget
build
(
BuildContext
context
)
=>
Container
();
}
}
class
TestChildWidget
extends
StatefulWidget
{
const
TestChildWidget
({
Key
key
})
:
super
(
key:
key
);
@override
TestChildState
createState
()
=>
TestChildState
();
}
class
TestChildState
extends
State
<
TestChildWidget
>
{
bool
toggle
=
true
;
void
toggleMe
()
{
setState
(()
{
toggle
=
!
toggle
;
});
}
@override
Widget
build
(
BuildContext
context
)
=>
toggle
?
const
SizedBox
()
:
const
Text
(
'CRASHHH'
);
}
void
main
(
)
{
void
main
(
)
{
testWidgets
(
'Table widget - empty'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Table widget - empty'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
...
@@ -855,5 +873,32 @@ void main() {
...
@@ -855,5 +873,32 @@ void main() {
);
);
});
});
// Regression test for https://github.com/flutter/flutter/issues/31473.
testWidgets
(
'Does not crash if a child RenderObject is replaced by another RenderObject of a different type'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Table
(
children:
const
<
TableRow
>[
TableRow
(
children:
<
Widget
>[
TestChildWidget
()])]),
),
);
expect
(
find
.
text
(
'CRASHHH'
),
findsNothing
);
final
TestChildState
state
=
tester
.
state
(
find
.
byType
(
TestChildWidget
));
state
.
toggleMe
();
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Table
(
children:
const
<
TableRow
>[
TableRow
(
children:
<
Widget
>[
TestChildWidget
()])]),
),
);
// Should not crash.
expect
(
find
.
text
(
'CRASHHH'
),
findsOneWidget
);
}
);
// TODO(ianh): Test handling of TableCell object
// TODO(ianh): Test handling of TableCell object
}
}
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