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
011331dc
Unverified
Commit
011331dc
authored
Sep 09, 2020
by
Haeseok Lee
Committed by
GitHub
Sep 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue, ReorderableListView destroys children even if their key-type wasn't changed (#64855)
parent
38834d36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
1 deletion
+86
-1
reorderable_list.dart
packages/flutter/lib/src/material/reorderable_list.dart
+28
-1
reorderable_list_test.dart
packages/flutter/test/material/reorderable_list_test.dart
+58
-0
No files found.
packages/flutter/lib/src/material/reorderable_list.dart
View file @
011331dc
...
...
@@ -363,7 +363,7 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
// Handles up the logic for dragging and reordering items in the list.
Widget
_wrap
(
Widget
toWrap
,
int
index
,
BoxConstraints
constraints
)
{
assert
(
toWrap
.
key
!=
null
);
final
GlobalObjectKey
keyIndexGlobalKey
=
GlobalObjectKey
(
toWrap
.
key
);
final
_ReorderableListViewChildGlobalKey
keyIndexGlobalKey
=
_ReorderableListViewChildGlobalKey
(
toWrap
.
key
,
this
);
// We pass the toWrapWithGlobalKey into the Draggable so that when a list
// item gets dragged, the accessibility framework can preserve the selected
// state of the dragging item.
...
...
@@ -596,3 +596,30 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
});
}
}
// A global key that takes its identity from the object and uses a value of a
// particular type to identify itself.
//
// The difference with GlobalObjectKey is that it uses [==] instead of [identical]
// of the objects used to generate widgets.
@optionalTypeArgs
class
_ReorderableListViewChildGlobalKey
extends
GlobalObjectKey
{
const
_ReorderableListViewChildGlobalKey
(
this
.
subKey
,
this
.
state
)
:
super
(
subKey
);
final
Key
subKey
;
final
_ReorderableListContentState
state
;
@override
bool
operator
==(
Object
other
)
{
if
(
other
.
runtimeType
!=
runtimeType
)
return
false
;
return
other
is
_ReorderableListViewChildGlobalKey
&&
other
.
subKey
==
subKey
&&
other
.
state
==
state
;
}
@override
int
get
hashCode
=>
hashValues
(
subKey
,
state
);
}
packages/flutter/test/material/reorderable_list_test.dart
View file @
011331dc
...
...
@@ -253,6 +253,35 @@ void main() {
expect
(
findState
(
const
Key
(
'A'
)).
checked
,
true
);
});
testWidgets
(
'Preserves children states when rebuilt'
,
(
WidgetTester
tester
)
async
{
const
Key
firstBox
=
Key
(
'key'
);
Widget
build
()
{
return
MaterialApp
(
home:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
SizedBox
(
width:
100
,
height:
100
,
child:
ReorderableListView
(
scrollDirection:
Axis
.
vertical
,
children:
const
<
Widget
>[
SizedBox
(
key:
firstBox
,
width:
10
,
height:
10
),
],
onReorder:
(
_
,
__
)
{},
),
),
),
);
}
// When the widget is rebuilt, the state of child should be consistent.
await
tester
.
pumpWidget
(
build
());
final
Element
e0
=
tester
.
element
(
find
.
byKey
(
firstBox
));
await
tester
.
pumpWidget
(
build
());
final
Element
e1
=
tester
.
element
(
find
.
byKey
(
firstBox
));
expect
(
e0
,
equals
(
e1
));
});
testWidgets
(
'Uses the PrimaryScrollController when available'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
primary
=
ScrollController
();
final
Widget
reorderableList
=
ReorderableListView
(
...
...
@@ -771,6 +800,35 @@ void main() {
expect
(
findState
(
const
Key
(
'A'
)).
checked
,
true
);
});
testWidgets
(
'Preserves children states when rebuilt'
,
(
WidgetTester
tester
)
async
{
const
Key
firstBox
=
Key
(
'key'
);
Widget
build
()
{
return
MaterialApp
(
home:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
SizedBox
(
width:
100
,
height:
100
,
child:
ReorderableListView
(
scrollDirection:
Axis
.
horizontal
,
children:
const
<
Widget
>[
SizedBox
(
key:
firstBox
,
width:
10
,
height:
10
),
],
onReorder:
(
_
,
__
)
{},
),
),
),
);
}
// When the widget is rebuilt, the state of child should be consistent.
await
tester
.
pumpWidget
(
build
());
final
Element
e0
=
tester
.
element
(
find
.
byKey
(
firstBox
));
await
tester
.
pumpWidget
(
build
());
final
Element
e1
=
tester
.
element
(
find
.
byKey
(
firstBox
));
expect
(
e0
,
equals
(
e1
));
});
group
(
'Accessibility (a11y/Semantics)'
,
()
{
Map
<
CustomSemanticsAction
,
VoidCallback
>
getSemanticsActions
(
int
index
)
{
final
Semantics
semantics
=
find
.
ancestor
(
...
...
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