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
aa0382e9
Unverified
Commit
aa0382e9
authored
Jun 26, 2020
by
Alberto Monteiro
Committed by
GitHub
Jun 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReorderableListView should not reorder if there is only a single item present (#59631)
parent
99f5eebc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
2 deletions
+61
-2
reorderable_list.dart
packages/flutter/lib/src/material/reorderable_list.dart
+7
-2
reorderable_list_test.dart
packages/flutter/test/material/reorderable_list_test.dart
+54
-0
No files found.
packages/flutter/lib/src/material/reorderable_list.dart
View file @
aa0382e9
...
...
@@ -574,6 +574,11 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
);
break
;
}
// If the reorderable list only has one child element, reordering
// should not be allowed.
final
bool
hasMoreThanOneChildElement
=
widget
.
children
.
length
>
1
;
return
SingleChildScrollView
(
scrollDirection:
widget
.
scrollDirection
,
padding:
widget
.
padding
,
...
...
@@ -581,10 +586,10 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
reverse:
widget
.
reverse
,
child:
_buildContainerForScrollDirection
(
children:
<
Widget
>[
if
(
widget
.
reverse
)
_wrap
(
finalDropArea
,
widget
.
children
.
length
,
constraints
),
if
(
widget
.
reverse
&&
hasMoreThanOneChildElement
)
_wrap
(
finalDropArea
,
widget
.
children
.
length
,
constraints
),
if
(
widget
.
header
!=
null
)
widget
.
header
,
for
(
int
i
=
0
;
i
<
widget
.
children
.
length
;
i
+=
1
)
_wrap
(
widget
.
children
[
i
],
i
,
constraints
),
if
(!
widget
.
reverse
)
_wrap
(
finalDropArea
,
widget
.
children
.
length
,
constraints
),
if
(!
widget
.
reverse
&&
hasMoreThanOneChildElement
)
_wrap
(
finalDropArea
,
widget
.
children
.
length
,
constraints
),
],
),
);
...
...
packages/flutter/test/material/reorderable_list_test.dart
View file @
aa0382e9
...
...
@@ -56,6 +56,33 @@ void main() {
});
group
(
'in vertical mode'
,
()
{
testWidgets
(
'reorder is not triggered when children length is less or equals to 1'
,
(
WidgetTester
tester
)
async
{
bool
onReorderWasCalled
=
false
;
final
List
<
String
>
currentListItems
=
listItems
.
take
(
1
).
toList
();
final
ReorderableListView
reorderableListView
=
ReorderableListView
(
header:
const
Text
(
'Header'
),
children:
currentListItems
.
map
<
Widget
>(
listItemToWidget
).
toList
(),
scrollDirection:
Axis
.
vertical
,
onReorder:
(
_
,
__
)
=>
onReorderWasCalled
=
true
,
);
final
List
<
String
>
currentOriginalListItems
=
originalListItems
.
take
(
1
).
toList
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
SizedBox
(
height:
itemHeight
*
10
,
child:
reorderableListView
,
),
));
expect
(
currentListItems
,
orderedEquals
(
currentOriginalListItems
));
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'Item 1'
)));
await
tester
.
pump
(
kLongPressTimeout
+
kPressTimeout
);
expect
(
currentListItems
,
orderedEquals
(
currentOriginalListItems
));
await
drag
.
moveTo
(
tester
.
getBottomLeft
(
find
.
text
(
'Item 1'
))
*
2
);
expect
(
currentListItems
,
orderedEquals
(
currentOriginalListItems
));
await
drag
.
up
();
expect
(
onReorderWasCalled
,
false
);
expect
(
currentListItems
,
orderedEquals
(<
String
>[
'Item 1'
]));
});
testWidgets
(
'reorders its contents only when a drag finishes'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
build
());
expect
(
listItems
,
orderedEquals
(
originalListItems
));
...
...
@@ -547,6 +574,33 @@ void main() {
});
group
(
'in horizontal mode'
,
()
{
testWidgets
(
'reorder is not triggered when children length is less or equals to 1'
,
(
WidgetTester
tester
)
async
{
bool
onReorderWasCalled
=
false
;
final
List
<
String
>
currentListItems
=
listItems
.
take
(
1
).
toList
();
final
ReorderableListView
reorderableListView
=
ReorderableListView
(
header:
const
Text
(
'Header'
),
children:
currentListItems
.
map
<
Widget
>(
listItemToWidget
).
toList
(),
scrollDirection:
Axis
.
horizontal
,
onReorder:
(
_
,
__
)
=>
onReorderWasCalled
=
true
,
);
final
List
<
String
>
currentOriginalListItems
=
originalListItems
.
take
(
1
).
toList
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
SizedBox
(
height:
itemHeight
*
10
,
child:
reorderableListView
,
),
));
expect
(
currentListItems
,
orderedEquals
(
currentOriginalListItems
));
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'Item 1'
)));
await
tester
.
pump
(
kLongPressTimeout
+
kPressTimeout
);
expect
(
currentListItems
,
orderedEquals
(
currentOriginalListItems
));
await
drag
.
moveTo
(
tester
.
getBottomLeft
(
find
.
text
(
'Item 1'
))
*
2
);
expect
(
currentListItems
,
orderedEquals
(
currentOriginalListItems
));
await
drag
.
up
();
expect
(
onReorderWasCalled
,
false
);
expect
(
currentListItems
,
orderedEquals
(<
String
>[
'Item 1'
]));
});
testWidgets
(
'allows reordering from the very top to the very bottom'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
build
(
scrollDirection:
Axis
.
horizontal
));
expect
(
listItems
,
orderedEquals
(
originalListItems
));
...
...
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