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
30678259
Commit
30678259
authored
Apr 05, 2019
by
Taym Haddadi
Committed by
Hans Muller
Apr 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add confirmDismiss example to flutter_gallery (#30497)
parent
e153883d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
leave_behind_demo.dart
.../flutter_gallery/lib/demo/material/leave_behind_demo.dart
+57
-1
No files found.
examples/flutter_gallery/lib/demo/material/leave_behind_demo.dart
View file @
30678259
...
...
@@ -13,7 +13,8 @@ enum LeaveBehindDemoAction {
reset
,
horizontalSwipe
,
leftSwipe
,
rightSwipe
rightSwipe
,
confirmDismiss
,
}
class
LeaveBehindItem
implements
Comparable
<
LeaveBehindItem
>
{
...
...
@@ -43,6 +44,7 @@ class LeaveBehindDemo extends StatefulWidget {
class
LeaveBehindDemoState
extends
State
<
LeaveBehindDemo
>
{
static
final
GlobalKey
<
ScaffoldState
>
_scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
DismissDirection
_dismissDirection
=
DismissDirection
.
horizontal
;
bool
_confirmDismiss
=
true
;
List
<
LeaveBehindItem
>
leaveBehindItems
;
void
initListItems
()
{
...
...
@@ -77,6 +79,9 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
case
LeaveBehindDemoAction
.
rightSwipe
:
_dismissDirection
=
DismissDirection
.
startToEnd
;
break
;
case
LeaveBehindDemoAction
.
confirmDismiss
:
_confirmDismiss
=
!
_confirmDismiss
;
break
;
}
});
}
...
...
@@ -128,6 +133,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
body
=
ListView
(
children:
leaveBehindItems
.
map
<
Widget
>((
LeaveBehindItem
item
)
{
return
_LeaveBehindListItem
(
confirmDismiss:
_confirmDismiss
,
item:
item
,
onArchive:
_handleArchive
,
onDelete:
_handleDelete
,
...
...
@@ -166,6 +172,11 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
checked:
_dismissDirection
==
DismissDirection
.
startToEnd
,
child:
const
Text
(
'Only swipe right'
),
),
CheckedPopupMenuItem
<
LeaveBehindDemoAction
>(
value:
LeaveBehindDemoAction
.
confirmDismiss
,
checked:
_confirmDismiss
,
child:
const
Text
(
'Confirm dismiss'
),
),
],
),
],
...
...
@@ -182,12 +193,14 @@ class _LeaveBehindListItem extends StatelessWidget {
@required
this
.
onArchive
,
@required
this
.
onDelete
,
@required
this
.
dismissDirection
,
@required
this
.
confirmDismiss
,
})
:
super
(
key:
key
);
final
LeaveBehindItem
item
;
final
DismissDirection
dismissDirection
;
final
void
Function
(
LeaveBehindItem
)
onArchive
;
final
void
Function
(
LeaveBehindItem
)
onDelete
;
final
bool
confirmDismiss
;
void
_handleArchive
()
{
onArchive
(
item
);
...
...
@@ -214,6 +227,23 @@ class _LeaveBehindListItem extends StatelessWidget {
else
_handleDelete
();
},
confirmDismiss:
!
confirmDismiss
?
null
:
(
DismissDirection
dismissDirection
)
async
{
switch
(
dismissDirection
)
{
case
DismissDirection
.
endToStart
:
if
(
await
_showConfirmationDialog
(
context
,
'archive'
))
_handleArchive
();
break
;
case
DismissDirection
.
startToEnd
:
if
(
await
_showConfirmationDialog
(
context
,
'delete'
))
_handleDelete
();
break
;
case
DismissDirection
.
horizontal
:
case
DismissDirection
.
vertical
:
case
DismissDirection
.
up
:
case
DismissDirection
.
down
:
assert
(
false
);
}
},
background:
Container
(
color:
theme
.
primaryColor
,
child:
const
ListTile
(
...
...
@@ -240,4 +270,30 @@ class _LeaveBehindListItem extends StatelessWidget {
),
);
}
Future
<
bool
>
_showConfirmationDialog
(
BuildContext
context
,
String
action
)
{
return
showDialog
<
bool
>(
context:
context
,
barrierDismissible:
true
,
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
title:
Text
(
'Do you want to
$action
this item?'
),
actions:
<
Widget
>[
FlatButton
(
child:
const
Text
(
'Yes'
),
onPressed:
()
{
Navigator
.
pop
(
context
,
true
);
// showDialog() returns true
},
),
FlatButton
(
child:
const
Text
(
'No'
),
onPressed:
()
{
Navigator
.
pop
(
context
,
false
);
// showDialog() returns false
},
),
],
);
},
);
}
}
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