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
7570495b
Commit
7570495b
authored
Apr 07, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SnackBarActions shouldn't be tappable twice
They should automagically disable after the first tap.
parent
1e207c01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
3 deletions
+68
-3
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+24
-3
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+44
-0
No files found.
packages/flutter/lib/src/material/snack_bar.dart
View file @
7570495b
...
@@ -36,11 +36,13 @@ const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOut
...
@@ -36,11 +36,13 @@ const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOut
/// Snack bar actions are always enabled. If you want to disable a snack bar
/// Snack bar actions are always enabled. If you want to disable a snack bar
/// action, simply don't include it in the snack bar.
/// action, simply don't include it in the snack bar.
///
///
/// Snack bar actions can only be pressed once. Subsequent presses are ignored.
///
/// See also:
/// See also:
///
///
/// * [SnackBar]
/// * [SnackBar]
/// * <https://www.google.com/design/spec/components/snackbars-toasts.html>
/// * <https://www.google.com/design/spec/components/snackbars-toasts.html>
class
SnackBarAction
extends
State
less
Widget
{
class
SnackBarAction
extends
State
ful
Widget
{
SnackBarAction
({
Key
key
,
this
.
label
,
this
.
onPressed
})
:
super
(
key:
key
)
{
SnackBarAction
({
Key
key
,
this
.
label
,
this
.
onPressed
})
:
super
(
key:
key
)
{
assert
(
label
!=
null
);
assert
(
label
!=
null
);
assert
(
onPressed
!=
null
);
assert
(
onPressed
!=
null
);
...
@@ -50,16 +52,35 @@ class SnackBarAction extends StatelessWidget {
...
@@ -50,16 +52,35 @@ class SnackBarAction extends StatelessWidget {
final
String
label
;
final
String
label
;
/// The callback to be invoked when the button is pressed. Must be non-null.
/// The callback to be invoked when the button is pressed. Must be non-null.
///
/// This callback will be invoked at most once each time this action is
/// displayed in a [SnackBar].
final
VoidCallback
onPressed
;
final
VoidCallback
onPressed
;
@override
_SnackBarActionState
createState
()
=>
new
_SnackBarActionState
();
}
class
_SnackBarActionState
extends
State
<
SnackBarAction
>
{
bool
_haveTriggeredAction
=
false
;
void
_handlePressed
()
{
if
(
_haveTriggeredAction
)
return
;
setState
(()
{
_haveTriggeredAction
=
true
;
});
config
.
onPressed
();
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
new
Container
(
return
new
Container
(
margin:
const
EdgeInsets
.
only
(
left:
_kSideMargins
),
margin:
const
EdgeInsets
.
only
(
left:
_kSideMargins
),
child:
new
FlatButton
(
child:
new
FlatButton
(
onPressed:
on
Pressed
,
onPressed:
_haveTriggeredAction
?
null
:
_handle
Pressed
,
textTheme:
ButtonColor
.
accent
,
textTheme:
ButtonColor
.
accent
,
child:
new
Text
(
label
)
child:
new
Text
(
config
.
label
)
)
)
);
);
}
}
...
...
packages/flutter/test/
widget
/snack_bar_test.dart
→
packages/flutter/test/
material
/snack_bar_test.dart
View file @
7570495b
...
@@ -282,4 +282,48 @@ void main() {
...
@@ -282,4 +282,48 @@ void main() {
});
});
});
});
test
(
'SnackBar cannot be tapped twice'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
int
tapCount
=
0
;
tester
.
pumpWidget
(
new
MaterialApp
(
routes:
<
String
,
WidgetBuilder
>{
'/'
:
(
BuildContext
context
)
{
return
new
Scaffold
(
body:
new
Builder
(
builder:
(
BuildContext
context
)
{
return
new
GestureDetector
(
onTap:
()
{
Scaffold
.
of
(
context
).
showSnackBar
(
new
SnackBar
(
content:
new
Text
(
'I am a snack bar.'
),
duration:
new
Duration
(
seconds:
2
),
action:
new
SnackBarAction
(
label:
'ACTION'
,
onPressed:
()
{
++
tapCount
;
}
)
));
},
child:
new
Text
(
'X'
)
);
}
)
);
}
}
));
tester
.
tap
(
tester
.
findText
(
'X'
));
tester
.
pump
();
// start animation
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
expect
(
tapCount
,
equals
(
0
));
tester
.
tap
(
tester
.
findText
(
'ACTION'
));
expect
(
tapCount
,
equals
(
1
));
tester
.
tap
(
tester
.
findText
(
'ACTION'
));
expect
(
tapCount
,
equals
(
1
));
tester
.
pump
();
tester
.
tap
(
tester
.
findText
(
'ACTION'
));
expect
(
tapCount
,
equals
(
1
));
});
});
}
}
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