Merge pull request #2482 from HansMuller/dismiss_action

Support undo in the leave-behind demo
diff --git a/examples/material_gallery/lib/demo/leave_behind_demo.dart b/examples/material_gallery/lib/demo/leave_behind_demo.dart
index 49337fb..c69c01b 100644
--- a/examples/material_gallery/lib/demo/leave_behind_demo.dart
+++ b/examples/material_gallery/lib/demo/leave_behind_demo.dart
@@ -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 @@
     }
   }
 
+  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 @@
         });
         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(
diff --git a/examples/material_gallery/lib/demo/snack_bar_demo.dart b/examples/material_gallery/lib/demo/snack_bar_demo.dart
index 19b9dc6..09b2d31 100644
--- a/examples/material_gallery/lib/demo/snack_bar_demo.dart
+++ b/examples/material_gallery/lib/demo/snack_bar_demo.dart
@@ -33,7 +33,7 @@
               Scaffold.of(context).showSnackBar(new SnackBar(
                 content: new Text('This is a SnackBar'),
                 action: new SnackBarAction(
-                  label: 'Action',
+                  label: 'ACTION',
                   onPressed: () {
                     Scaffold.of(context).showSnackBar(new SnackBar(
                       content: new Text("You pressed the SnackBar's Action")
diff --git a/examples/material_gallery/pubspec.yaml b/examples/material_gallery/pubspec.yaml
index 7928aa2..06c5b03 100644
--- a/examples/material_gallery/pubspec.yaml
+++ b/examples/material_gallery/pubspec.yaml
@@ -1,6 +1,7 @@
 name: material_gallery
 dependencies:
   intl: '>=0.12.4+2 <0.13.0'
+  collection: '>=1.4.0 <2.0.0'
 
   flutter:
     path: ../../packages/flutter
diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart
index 82d9550..d6925e3 100644
--- a/examples/widgets/card_collection.dart
+++ b/examples/widgets/card_collection.dart
@@ -298,7 +298,7 @@
     Widget card = new Dismissable(
       key: new ObjectKey(cardModel),
       direction: _dismissDirection,
-      onResized: () { _invalidator(<int>[index]); },
+      onResize: () { _invalidator(<int>[index]); },
       onDismissed: (DismissDirection direction) { dismissCard(cardModel); },
       child: new Card(
         color: _primaryColor[cardModel.color],
diff --git a/packages/flutter/lib/src/widgets/dismissable.dart b/packages/flutter/lib/src/widgets/dismissable.dart
index 7676f4b..d17eb78 100644
--- a/packages/flutter/lib/src/widgets/dismissable.dart
+++ b/packages/flutter/lib/src/widgets/dismissable.dart
@@ -58,7 +58,7 @@
     this.child,
     this.background,
     this.secondaryBackground,
-    this.onResized,
+    this.onResize,
     this.onDismissed,
     this.direction: DismissDirection.horizontal
   }) : super(key: key) {
@@ -79,7 +79,7 @@
   final Widget secondaryBackground;
 
   /// Called when the widget changes size (i.e., when contracting before being dismissed).
-  final VoidCallback onResized;
+  final VoidCallback onResize;
 
   /// Called when the widget has been dismissed, after finishing resizing.
   final DismissDirectionCallback onDismissed;
@@ -263,12 +263,11 @@
 
   void _handleResizeProgressChanged() {
     if (_resizeController.isCompleted) {
-      if (config.onDismissed != null) {
+      if (config.onDismissed != null)
         config.onDismissed(_dismissDirection);
-      }
     } else {
-      if (config.onResized != null)
-        config.onResized();
+      if (config.onResize != null)
+        config.onResize();
     }
   }
 
diff --git a/packages/flutter/test/widget/dismissable_test.dart b/packages/flutter/test/widget/dismissable_test.dart
index 4610f07..8871277 100644
--- a/packages/flutter/test/widget/dismissable_test.dart
+++ b/packages/flutter/test/widget/dismissable_test.dart
@@ -13,7 +13,7 @@
 DismissDirection reportedDismissDirection;
 List<int> dismissedItems = <int>[];
 
-void handleOnResized(int item) {
+void handleOnResize(int item) {
   expect(dismissedItems.contains(item), isFalse);
 }
 
@@ -28,7 +28,7 @@
     key: new ValueKey<int>(item),
     direction: dismissDirection,
     onDismissed: (DismissDirection direction) { handleOnDismissed(direction, item); },
-    onResized: () { handleOnResized(item); },
+    onResize: () { handleOnResize(item); },
     child: new Container(
       width: itemExtent,
       height: itemExtent,