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
73d7378c
Commit
73d7378c
authored
Mar 08, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support undo in the leave-behind demo
parent
33ab0ee6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
11 deletions
+26
-11
leave_behind_demo.dart
examples/material_gallery/lib/demo/leave_behind_demo.dart
+16
-1
snack_bar_demo.dart
examples/material_gallery/lib/demo/snack_bar_demo.dart
+1
-1
pubspec.yaml
examples/material_gallery/pubspec.yaml
+1
-0
card_collection.dart
examples/widgets/card_collection.dart
+1
-1
dismissable.dart
packages/flutter/lib/src/widgets/dismissable.dart
+5
-6
dismissable_test.dart
packages/flutter/test/widget/dismissable_test.dart
+2
-2
No files found.
examples/material_gallery/lib/demo/leave_behind_demo.dart
View file @
73d7378c
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:collection/collection.dart'
show
lowerBound
;
import
'package:flutter/material.dart'
;
enum
LeaveBehindDemoAction
{
...
...
@@ -67,6 +69,15 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
}
}
void
handleUndo
(
LeaveBehindItem
item
)
{
int
insertionIndex
=
lowerBound
(
leaveBehindItems
,
item
,
compare:
(
LeaveBehindItem
a
,
LeaveBehindItem
b
)
=>
a
.
index
.
compareTo
(
b
.
index
)
);
setState
(()
{
leaveBehindItems
.
insert
(
insertionIndex
,
item
);
});
}
Widget
buildItem
(
LeaveBehindItem
item
)
{
final
ThemeData
theme
=
Theme
.
of
(
context
);
return
new
Dismissable
(
...
...
@@ -78,7 +89,11 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
});
final
String
action
=
(
direction
==
DismissDirection
.
left
)
?
'archived'
:
'deleted'
;
_scaffoldKey
.
currentState
.
showSnackBar
(
new
SnackBar
(
content:
new
Text
(
'You
$action
item
${item.index}
'
)
content:
new
Text
(
'You
$action
item
${item.index}
'
),
action:
new
SnackBarAction
(
label:
'UNDO'
,
onPressed:
()
{
handleUndo
(
item
);
}
)
));
},
background:
new
Container
(
...
...
examples/material_gallery/lib/demo/snack_bar_demo.dart
View file @
73d7378c
...
...
@@ -33,7 +33,7 @@ class SnackBarDemo extends StatelessComponent {
Scaffold
.
of
(
context
).
showSnackBar
(
new
SnackBar
(
content:
new
Text
(
'This is a SnackBar'
),
action:
new
SnackBarAction
(
label:
'A
ction
'
,
label:
'A
CTION
'
,
onPressed:
()
{
Scaffold
.
of
(
context
).
showSnackBar
(
new
SnackBar
(
content:
new
Text
(
"You pressed the SnackBar's Action"
)
...
...
examples/material_gallery/pubspec.yaml
View file @
73d7378c
name
:
material_gallery
dependencies
:
intl
:
'
>=0.12.4+2
<0.13.0'
collection
:
'
>=1.4.0
<2.0.0'
flutter
:
path
:
../../packages/flutter
...
...
examples/widgets/card_collection.dart
View file @
73d7378c
...
...
@@ -298,7 +298,7 @@ class CardCollectionState extends State<CardCollection> {
Widget
card
=
new
Dismissable
(
key:
new
ObjectKey
(
cardModel
),
direction:
_dismissDirection
,
onResize
d
:
()
{
_invalidator
(<
int
>[
index
]);
},
onResize:
()
{
_invalidator
(<
int
>[
index
]);
},
onDismissed:
(
DismissDirection
direction
)
{
dismissCard
(
cardModel
);
},
child:
new
Card
(
color:
_primaryColor
[
cardModel
.
color
],
...
...
packages/flutter/lib/src/widgets/dismissable.dart
View file @
73d7378c
...
...
@@ -58,7 +58,7 @@ class Dismissable extends StatefulComponent {
this
.
child
,
this
.
background
,
this
.
secondaryBackground
,
this
.
onResize
d
,
this
.
onResize
,
this
.
onDismissed
,
this
.
direction
:
DismissDirection
.
horizontal
})
:
super
(
key:
key
)
{
...
...
@@ -79,7 +79,7 @@ class Dismissable extends StatefulComponent {
final
Widget
secondaryBackground
;
/// Called when the widget changes size (i.e., when contracting before being dismissed).
final
VoidCallback
onResize
d
;
final
VoidCallback
onResize
;
/// Called when the widget has been dismissed, after finishing resizing.
final
DismissDirectionCallback
onDismissed
;
...
...
@@ -263,12 +263,11 @@ class _DismissableState extends State<Dismissable> {
void
_handleResizeProgressChanged
()
{
if
(
_resizeController
.
isCompleted
)
{
if
(
config
.
onDismissed
!=
null
)
{
if
(
config
.
onDismissed
!=
null
)
config
.
onDismissed
(
_dismissDirection
);
}
}
else
{
if
(
config
.
onResize
d
!=
null
)
config
.
onResize
d
();
if
(
config
.
onResize
!=
null
)
config
.
onResize
();
}
}
...
...
packages/flutter/test/widget/dismissable_test.dart
View file @
73d7378c
...
...
@@ -13,7 +13,7 @@ DismissDirection dismissDirection = DismissDirection.horizontal;
DismissDirection
reportedDismissDirection
;
List
<
int
>
dismissedItems
=
<
int
>[];
void
handleOnResize
d
(
int
item
)
{
void
handleOnResize
(
int
item
)
{
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
}
...
...
@@ -28,7 +28,7 @@ Widget buildDismissableItem(int item) {
key:
new
ValueKey
<
int
>(
item
),
direction:
dismissDirection
,
onDismissed:
(
DismissDirection
direction
)
{
handleOnDismissed
(
direction
,
item
);
},
onResize
d:
()
{
handleOnResized
(
item
);
},
onResize
:
()
{
handleOnResize
(
item
);
},
child:
new
Container
(
width:
itemExtent
,
height:
itemExtent
,
...
...
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