SnackBar should have a single optional action The example in the spec with multiple actions is an anti-example. Fixes #1876
diff --git a/examples/fitness/lib/feed.dart b/examples/fitness/lib/feed.dart index 74f7dbd..2af97fe 100644 --- a/examples/fitness/lib/feed.dart +++ b/examples/fitness/lib/feed.dart
@@ -110,11 +110,12 @@ config.onItemDeleted(item); Scaffold.of(context).showSnackBar(new SnackBar( content: new Text("Item deleted."), - actions: <SnackBarAction>[ - new SnackBarAction(label: "UNDO", onPressed: () { + action: new SnackBarAction( + label: "UNDO", + onPressed: () { config.onItemCreated(item); - }), - ] + } + ) )); }
diff --git a/examples/material_gallery/lib/demo/snack_bar_demo.dart b/examples/material_gallery/lib/demo/snack_bar_demo.dart index de0a9a0..19b9dc6 100644 --- a/examples/material_gallery/lib/demo/snack_bar_demo.dart +++ b/examples/material_gallery/lib/demo/snack_bar_demo.dart
@@ -32,16 +32,14 @@ onPressed: () { Scaffold.of(context).showSnackBar(new SnackBar( content: new Text('This is a SnackBar'), - actions: <SnackBarAction>[ - new SnackBarAction( - label: 'Action', - onPressed: () { - Scaffold.of(context).showSnackBar(new SnackBar( - content: new Text("You pressed the SnackBar's Action") - )); - } - ) - ] + action: new SnackBarAction( + label: 'Action', + onPressed: () { + Scaffold.of(context).showSnackBar(new SnackBar( + content: new Text("You pressed the SnackBar's Action") + )); + } + ) )); } ),
diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index e90edb3..d76e3b1 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart
@@ -210,9 +210,12 @@ }); _scaffoldKey.currentState.showSnackBar(new SnackBar( content: new Text("Purchased ${stock.symbol} for ${stock.lastSale}"), - actions: <SnackBarAction>[ - new SnackBarAction(label: "BUY MORE", onPressed: () { _buyStock(stock, arrowKey); }) - ] + action: new SnackBarAction( + label: "BUY MORE", + onPressed: () { + _buyStock(stock, arrowKey); + } + ) )); }
diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index e06d38a..64e4b58 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart
@@ -74,7 +74,7 @@ SnackBar({ Key key, this.content, - this.actions, + this.action, this.duration: kSnackBarShortDisplayDuration, this.animation }) : super(key: key) { @@ -82,7 +82,7 @@ } final Widget content; - final List<SnackBarAction> actions; + final SnackBarAction action; final Duration duration; final Animation<double> animation; @@ -99,8 +99,8 @@ ) ) ]; - if (actions != null) - children.addAll(actions); + if (action != null) + children.add(action); CurvedAnimation heightAnimation = new CurvedAnimation(parent: animation, curve: _snackBarHeightCurve); CurvedAnimation fadeAnimation = new CurvedAnimation(parent: animation, curve: _snackBarFadeCurve); ThemeData theme = Theme.of(context); @@ -156,7 +156,7 @@ return new SnackBar( key: key ?? fallbackKey, content: content, - actions: actions, + action: action, duration: duration, animation: newAnimation );