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
f4604fe0
Unverified
Commit
f4604fe0
authored
Jun 09, 2022
by
Taha Tesser
Committed by
GitHub
Jun 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `SliverReorderableList` item dispose (#105097)
parent
b0edb5e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
23 deletions
+93
-23
reorderable_list.dart
packages/flutter/lib/src/widgets/reorderable_list.dart
+26
-23
reorderable_list_test.dart
packages/flutter/test/widgets/reorderable_list_test.dart
+67
-0
No files found.
packages/flutter/lib/src/widgets/reorderable_list.dart
View file @
f4604fe0
...
...
@@ -603,8 +603,7 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
@override
void
dispose
()
{
_dragInfo
?.
dispose
();
_autoScroller
?.
stopAutoScroll
();
_dragReset
();
super
.
dispose
();
}
...
...
@@ -658,7 +657,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
///
/// If no drag is active, this will do nothing.
void
cancelReorder
()
{
_dragReset
();
setState
(()
{
_dragReset
();
});
}
void
_registerItem
(
_ReorderableItemState
item
)
{
...
...
@@ -724,7 +725,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
}
void
_dragCancel
(
_DragInfo
item
)
{
_dragReset
();
setState
(()
{
_dragReset
();
});
}
void
_dragEnd
(
_DragInfo
item
)
{
...
...
@@ -753,29 +756,29 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
if
(
fromIndex
!=
toIndex
)
{
widget
.
onReorder
.
call
(
fromIndex
,
toIndex
);
}
_dragReset
();
setState
(()
{
_dragReset
();
});
}
void
_dragReset
()
{
setState
(()
{
if
(
_dragInfo
!=
null
)
{
if
(
_dragIndex
!=
null
&&
_items
.
containsKey
(
_dragIndex
))
{
final
_ReorderableItemState
dragItem
=
_items
[
_dragIndex
!]!;
dragItem
.
_dragging
=
false
;
dragItem
.
rebuild
();
_dragIndex
=
null
;
}
_dragInfo
?.
dispose
();
_dragInfo
=
null
;
_autoScroller
?.
stopAutoScroll
();
_resetItemGap
();
_recognizer
?.
dispose
();
_recognizer
=
null
;
_overlayEntry
?.
remove
();
_overlayEntry
=
null
;
_finalDropPosition
=
null
;
if
(
_dragInfo
!=
null
)
{
if
(
_dragIndex
!=
null
&&
_items
.
containsKey
(
_dragIndex
))
{
final
_ReorderableItemState
dragItem
=
_items
[
_dragIndex
!]!;
dragItem
.
_dragging
=
false
;
dragItem
.
rebuild
();
_dragIndex
=
null
;
}
});
_dragInfo
?.
dispose
();
_dragInfo
=
null
;
_autoScroller
?.
stopAutoScroll
();
_resetItemGap
();
_recognizer
?.
dispose
();
_recognizer
=
null
;
_overlayEntry
?.
remove
();
_overlayEntry
=
null
;
_finalDropPosition
=
null
;
}
}
void
_resetItemGap
()
{
...
...
packages/flutter/test/widgets/reorderable_list_test.dart
View file @
f4604fe0
...
...
@@ -1005,6 +1005,73 @@ void main() {
expect
(
items
,
orderedEquals
(<
int
>[
0
,
1
,
2
,
3
,
4
]));
});
});
testWidgets
(
'SliverReorderableList properly disposes items'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/105010
const
int
itemCount
=
5
;
final
List
<
int
>
items
=
List
<
int
>.
generate
(
itemCount
,
(
int
index
)
=>
index
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(),
drawer:
Drawer
(
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
Column
(
children:
<
Widget
>[
Expanded
(
child:
CustomScrollView
(
slivers:
<
Widget
>[
SliverReorderableList
(
itemCount:
itemCount
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Material
(
key:
ValueKey
<
String
>(
'item-
$index
'
),
child:
ReorderableDragStartListener
(
index:
index
,
child:
ListTile
(
title:
Text
(
'item
${items[index]}
'
),
),
),
);
},
onReorder:
(
int
oldIndex
,
int
newIndex
)
{},
),
],
),
),
TextButton
(
onPressed:
()
{
Scaffold
.
of
(
context
).
closeDrawer
();
},
child:
const
Text
(
'Close drawer'
),
),
],
);
}
),
),
),
),
);
await
tester
.
tap
(
find
.
byIcon
(
Icons
.
menu
));
await
tester
.
pumpAndSettle
();
final
Finder
item0
=
find
.
text
(
'item 0'
);
expect
(
item0
,
findsOneWidget
);
// Start gesture on first item without drag up event.
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
item0
));
await
drag
.
moveBy
(
const
Offset
(
0
,
200
));
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'Close drawer'
));
await
tester
.
pumpAndSettle
();
expect
(
item0
,
findsNothing
);
});
}
class
TestList
extends
StatefulWidget
{
...
...
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