Commit 72fcbb7d authored by Adam Barth's avatar Adam Barth

SnackBar should have a single optional action

The example in the spec with multiple actions is an anti-example.

Fixes #1876
parent 9e56fc4e
...@@ -110,11 +110,12 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -110,11 +110,12 @@ class FeedFragmentState extends State<FeedFragment> {
config.onItemDeleted(item); config.onItemDeleted(item);
Scaffold.of(context).showSnackBar(new SnackBar( Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text("Item deleted."), content: new Text("Item deleted."),
actions: <SnackBarAction>[ action: new SnackBarAction(
new SnackBarAction(label: "UNDO", onPressed: () { label: "UNDO",
onPressed: () {
config.onItemCreated(item); config.onItemCreated(item);
}), }
] )
)); ));
} }
......
...@@ -32,16 +32,14 @@ class SnackBarDemo extends StatelessComponent { ...@@ -32,16 +32,14 @@ class SnackBarDemo extends StatelessComponent {
onPressed: () { onPressed: () {
Scaffold.of(context).showSnackBar(new SnackBar( Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('This is a SnackBar'), content: new Text('This is a SnackBar'),
actions: <SnackBarAction>[ action: new SnackBarAction(
new SnackBarAction( label: 'Action',
label: 'Action', onPressed: () {
onPressed: () { Scaffold.of(context).showSnackBar(new SnackBar(
Scaffold.of(context).showSnackBar(new SnackBar( content: new Text("You pressed the SnackBar's Action")
content: new Text("You pressed the SnackBar's Action") ));
)); }
} )
)
]
)); ));
} }
), ),
......
...@@ -210,9 +210,12 @@ class StockHomeState extends State<StockHome> { ...@@ -210,9 +210,12 @@ class StockHomeState extends State<StockHome> {
}); });
_scaffoldKey.currentState.showSnackBar(new SnackBar( _scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text("Purchased ${stock.symbol} for ${stock.lastSale}"), content: new Text("Purchased ${stock.symbol} for ${stock.lastSale}"),
actions: <SnackBarAction>[ action: new SnackBarAction(
new SnackBarAction(label: "BUY MORE", onPressed: () { _buyStock(stock, arrowKey); }) label: "BUY MORE",
] onPressed: () {
_buyStock(stock, arrowKey);
}
)
)); ));
} }
......
...@@ -74,7 +74,7 @@ class SnackBar extends StatelessComponent { ...@@ -74,7 +74,7 @@ class SnackBar extends StatelessComponent {
SnackBar({ SnackBar({
Key key, Key key,
this.content, this.content,
this.actions, this.action,
this.duration: kSnackBarShortDisplayDuration, this.duration: kSnackBarShortDisplayDuration,
this.animation this.animation
}) : super(key: key) { }) : super(key: key) {
...@@ -82,7 +82,7 @@ class SnackBar extends StatelessComponent { ...@@ -82,7 +82,7 @@ class SnackBar extends StatelessComponent {
} }
final Widget content; final Widget content;
final List<SnackBarAction> actions; final SnackBarAction action;
final Duration duration; final Duration duration;
final Animation<double> animation; final Animation<double> animation;
...@@ -99,8 +99,8 @@ class SnackBar extends StatelessComponent { ...@@ -99,8 +99,8 @@ class SnackBar extends StatelessComponent {
) )
) )
]; ];
if (actions != null) if (action != null)
children.addAll(actions); children.add(action);
CurvedAnimation heightAnimation = new CurvedAnimation(parent: animation, curve: _snackBarHeightCurve); CurvedAnimation heightAnimation = new CurvedAnimation(parent: animation, curve: _snackBarHeightCurve);
CurvedAnimation fadeAnimation = new CurvedAnimation(parent: animation, curve: _snackBarFadeCurve); CurvedAnimation fadeAnimation = new CurvedAnimation(parent: animation, curve: _snackBarFadeCurve);
ThemeData theme = Theme.of(context); ThemeData theme = Theme.of(context);
...@@ -156,7 +156,7 @@ class SnackBar extends StatelessComponent { ...@@ -156,7 +156,7 @@ class SnackBar extends StatelessComponent {
return new SnackBar( return new SnackBar(
key: key ?? fallbackKey, key: key ?? fallbackKey,
content: content, content: content,
actions: actions, action: action,
duration: duration, duration: duration,
animation: newAnimation animation: newAnimation
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment