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
43d06c8e
Unverified
Commit
43d06c8e
authored
May 11, 2021
by
Valentin Vignal
Committed by
GitHub
May 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add draggable parameter to ReorderableDragStartListener (#81396)
parent
aa81ac60
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
201 additions
and
2 deletions
+201
-2
reorderable_list.dart
packages/flutter/lib/src/widgets/reorderable_list.dart
+10
-2
reorderable_list_test.dart
packages/flutter/test/widgets/reorderable_list_test.dart
+191
-0
No files found.
packages/flutter/lib/src/widgets/reorderable_list.dart
View file @
43d06c8e
...
...
@@ -1050,6 +1050,7 @@ class ReorderableDragStartListener extends StatelessWidget {
Key
?
key
,
required
this
.
child
,
required
this
.
index
,
this
.
enabled
=
true
,
})
:
super
(
key:
key
);
/// The widget for which the application would like to respond to a tap and
...
...
@@ -1059,10 +1060,16 @@ class ReorderableDragStartListener extends StatelessWidget {
/// The index of the associated item that will be dragged in the list.
final
int
index
;
/// Whether the [child] item can be dragged and moved in the list.
///
/// If true, the item can be moved to another location in the list when the
/// user taps on the child. If false, tapping on the child will be ignored.
final
bool
enabled
;
@override
Widget
build
(
BuildContext
context
)
{
return
Listener
(
onPointerDown:
(
PointerDownEvent
event
)
=>
_startDragging
(
context
,
event
)
,
onPointerDown:
enabled
?
(
PointerDownEvent
event
)
=>
_startDragging
(
context
,
event
)
:
null
,
child:
child
,
);
}
...
...
@@ -1111,7 +1118,8 @@ class ReorderableDelayedDragStartListener extends ReorderableDragStartListener {
Key
?
key
,
required
Widget
child
,
required
int
index
,
})
:
super
(
key:
key
,
child:
child
,
index:
index
);
bool
enabled
=
true
,
})
:
super
(
key:
key
,
child:
child
,
index:
index
,
enabled:
enabled
);
@override
MultiDragGestureRecognizer
createRecognizer
()
{
...
...
packages/flutter/test/widgets/reorderable_list_test.dart
View file @
43d06c8e
...
...
@@ -394,6 +394,197 @@ void main() {
expect
(
item1Height
,
30.0
);
expect
(
item2Height
,
30.0
);
});
group
(
'ReorderableDragStartListener'
,
()
{
testWidgets
(
'It should allow the item to be dragged when enabled is true'
,
(
WidgetTester
tester
)
async
{
const
int
itemCount
=
5
;
int
onReorderCallCount
=
0
;
final
List
<
int
>
items
=
List
<
int
>.
generate
(
itemCount
,
(
int
index
)
=>
index
);
void
handleReorder
(
int
fromIndex
,
int
toIndex
)
{
onReorderCallCount
+=
1
;
if
(
toIndex
>
fromIndex
)
{
toIndex
-=
1
;
}
items
.
insert
(
toIndex
,
items
.
removeAt
(
fromIndex
));
}
// The list has five elements of height 100
await
tester
.
pumpWidget
(
MaterialApp
(
home:
ReorderableList
(
itemCount:
itemCount
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
SizedBox
(
key:
ValueKey
<
int
>(
items
[
index
]),
height:
100
,
child:
ReorderableDragStartListener
(
child:
Text
(
'item
${items[index]}
'
),
index:
index
,
),
);
},
onReorder:
handleReorder
,
),
),
);
// Start gesture on first item
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'item 0'
)));
await
tester
.
pump
(
kPressTimeout
);
// Drag enough to move down the first item
await
drag
.
moveBy
(
const
Offset
(
0
,
150
));
await
tester
.
pump
();
await
drag
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
onReorderCallCount
,
1
);
expect
(
items
,
orderedEquals
(<
int
>[
1
,
0
,
2
,
3
,
4
]));
});
testWidgets
(
'It should allow the item to be dragged when enabled is true'
,
(
WidgetTester
tester
)
async
{
const
int
itemCount
=
5
;
int
onReorderCallCount
=
0
;
final
List
<
int
>
items
=
List
<
int
>.
generate
(
itemCount
,
(
int
index
)
=>
index
);
void
handleReorder
(
int
fromIndex
,
int
toIndex
)
{
onReorderCallCount
+=
1
;
if
(
toIndex
>
fromIndex
)
{
toIndex
-=
1
;
}
items
.
insert
(
toIndex
,
items
.
removeAt
(
fromIndex
));
}
// The list has five elements of height 100
await
tester
.
pumpWidget
(
MaterialApp
(
home:
ReorderableList
(
itemCount:
itemCount
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
SizedBox
(
key:
ValueKey
<
int
>(
items
[
index
]),
height:
100
,
child:
ReorderableDragStartListener
(
child:
Text
(
'item
${items[index]}
'
),
index:
index
,
enabled:
false
,
),
);
},
onReorder:
handleReorder
,
),
),
);
// Start gesture on first item
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'item 0'
)));
await
tester
.
pump
(
kLongPressTimeout
);
// Drag enough to move down the first item
await
drag
.
moveBy
(
const
Offset
(
0
,
150
));
await
tester
.
pump
();
await
drag
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
onReorderCallCount
,
0
);
expect
(
items
,
orderedEquals
(<
int
>[
0
,
1
,
2
,
3
,
4
]));
});
});
group
(
'ReorderableDelayedDragStartListener'
,
()
{
testWidgets
(
'It should allow the item to be dragged when enabled is true'
,
(
WidgetTester
tester
)
async
{
const
int
itemCount
=
5
;
int
onReorderCallCount
=
0
;
final
List
<
int
>
items
=
List
<
int
>.
generate
(
itemCount
,
(
int
index
)
=>
index
);
void
handleReorder
(
int
fromIndex
,
int
toIndex
)
{
onReorderCallCount
+=
1
;
if
(
toIndex
>
fromIndex
)
{
toIndex
-=
1
;
}
items
.
insert
(
toIndex
,
items
.
removeAt
(
fromIndex
));
}
// The list has five elements of height 100
await
tester
.
pumpWidget
(
MaterialApp
(
home:
ReorderableList
(
itemCount:
itemCount
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
SizedBox
(
key:
ValueKey
<
int
>(
items
[
index
]),
height:
100
,
child:
ReorderableDelayedDragStartListener
(
child:
Text
(
'item
${items[index]}
'
),
index:
index
,
),
);
},
onReorder:
handleReorder
,
),
),
);
await
tester
.
pumpAndSettle
();
// Start gesture on first item
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'item 0'
)));
await
tester
.
pump
(
kLongPressTimeout
);
// Drag enough to move down the first item
await
drag
.
moveBy
(
const
Offset
(
0
,
50
));
await
tester
.
pump
();
await
drag
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
onReorderCallCount
,
1
);
expect
(
items
,
orderedEquals
(<
int
>[
1
,
0
,
2
,
3
,
4
]));
});
testWidgets
(
'It should allow the item to be dragged when enabled is true'
,
(
WidgetTester
tester
)
async
{
const
int
itemCount
=
5
;
int
onReorderCallCount
=
0
;
final
List
<
int
>
items
=
List
<
int
>.
generate
(
itemCount
,
(
int
index
)
=>
index
);
void
handleReorder
(
int
fromIndex
,
int
toIndex
)
{
onReorderCallCount
+=
1
;
if
(
toIndex
>
fromIndex
)
{
toIndex
-=
1
;
}
items
.
insert
(
toIndex
,
items
.
removeAt
(
fromIndex
));
}
// The list has five elements of height 100
await
tester
.
pumpWidget
(
MaterialApp
(
home:
ReorderableList
(
itemCount:
itemCount
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
SizedBox
(
key:
ValueKey
<
int
>(
items
[
index
]),
height:
100
,
child:
ReorderableDelayedDragStartListener
(
child:
Text
(
'item
${items[index]}
'
),
index:
index
,
enabled:
false
,
),
);
},
onReorder:
handleReorder
,
),
),
);
// Start gesture on first item
final
TestGesture
drag
=
await
tester
.
startGesture
(
tester
.
getCenter
(
find
.
text
(
'item 0'
)));
await
tester
.
pump
(
kLongPressTimeout
);
// Drag enough to move down the first item
await
drag
.
moveBy
(
const
Offset
(
0
,
50
));
await
tester
.
pump
();
await
drag
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
onReorderCallCount
,
0
);
expect
(
items
,
orderedEquals
(<
int
>[
0
,
1
,
2
,
3
,
4
]));
});
});
}
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