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
44cd57f2
Commit
44cd57f2
authored
Mar 03, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DismissDirection onDismissed() callback parameter
parent
e9e7f44d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
6 deletions
+22
-6
card_collection.dart
examples/widgets/card_collection.dart
+1
-1
dismissable.dart
packages/flutter/lib/src/widgets/dismissable.dart
+11
-3
dismissable_test.dart
packages/flutter/test/widget/dismissable_test.dart
+10
-2
No files found.
examples/widgets/card_collection.dart
View file @
44cd57f2
...
...
@@ -298,7 +298,7 @@ class CardCollectionState extends State<CardCollection> {
Widget
card
=
new
Dismissable
(
direction:
_dismissDirection
,
onResized:
()
{
_invalidator
(<
int
>[
index
]);
},
onDismissed:
()
{
dismissCard
(
cardModel
);
},
onDismissed:
(
DismissDirection
direction
)
{
dismissCard
(
cardModel
);
},
child:
new
Card
(
color:
_primaryColor
[
cardModel
.
color
],
child:
new
Container
(
...
...
packages/flutter/lib/src/widgets/dismissable.dart
View file @
44cd57f2
...
...
@@ -15,6 +15,8 @@ const double _kMinFlingVelocityDelta = 400.0;
const
double
_kFlingVelocityScale
=
1.0
/
300.0
;
const
double
_kDismissCardThreshold
=
0.4
;
typedef
void
DismissDirectionCallback
(
DismissDirection
direction
);
/// The direction in which a [Dismissable] can be dismissed.
enum
DismissDirection
{
/// The [Dismissable] can be dismissed by dragging either up or down.
...
...
@@ -57,7 +59,7 @@ class Dismissable extends StatefulComponent {
final
VoidCallback
onResized
;
/// Called when the widget has been dismissed, after finishing resizing.
final
Void
Callback
onDismissed
;
final
DismissDirection
Callback
onDismissed
;
/// The direction in which the widget can be dismissed.
final
DismissDirection
direction
;
...
...
@@ -232,8 +234,14 @@ class _DismissableState extends State<Dismissable> {
void
_handleResizeProgressChanged
()
{
if
(
_resizeController
.
isCompleted
)
{
if
(
config
.
onDismissed
!=
null
)
config
.
onDismissed
();
if
(
config
.
onDismissed
!=
null
)
{
DismissDirection
direction
;
if
(
_directionIsXAxis
)
direction
=
_dragExtent
>
0
?
DismissDirection
.
right
:
DismissDirection
.
left
;
else
direction
=
_dragExtent
>
0
?
DismissDirection
.
down
:
DismissDirection
.
up
;
config
.
onDismissed
(
direction
);
}
}
else
{
if
(
config
.
onResized
!=
null
)
config
.
onResized
();
...
...
packages/flutter/test/widget/dismissable_test.dart
View file @
44cd57f2
...
...
@@ -10,13 +10,15 @@ import 'package:test/test.dart';
const
double
itemExtent
=
100.0
;
Axis
scrollDirection
=
Axis
.
vertical
;
DismissDirection
dismissDirection
=
DismissDirection
.
horizontal
;
DismissDirection
reportedDismissDirection
;
List
<
int
>
dismissedItems
=
<
int
>[];
void
handleOnResized
(
int
item
)
{
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
}
void
handleOnDismissed
(
int
item
)
{
void
handleOnDismissed
(
DismissDirection
direction
,
int
item
)
{
reportedDismissDirection
=
direction
;
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
dismissedItems
.
add
(
item
);
}
...
...
@@ -25,7 +27,7 @@ Widget buildDismissableItem(int item) {
return
new
Dismissable
(
key:
new
ValueKey
<
int
>(
item
),
direction:
dismissDirection
,
onDismissed:
(
)
{
handleOnDismissed
(
item
);
},
onDismissed:
(
DismissDirection
direction
)
{
handleOnDismissed
(
direction
,
item
);
},
onResized:
()
{
handleOnResized
(
item
);
},
child:
new
Container
(
width:
itemExtent
,
...
...
@@ -129,10 +131,12 @@ void main() {
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
right
);
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
left
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
left
);
});
});
...
...
@@ -148,10 +152,12 @@ void main() {
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
up
);
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
down
);
});
});
...
...
@@ -167,10 +173,12 @@ void main() {
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
right
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
left
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
left
);
});
});
...
...
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