Scaffold: animate the FloatingActionButton with the SnackBar.
This introduces the concept of an Anchor, which you can use to link transitions together. I've used this in the Fitness and Stocks apps to link the FAB and SnackBar to animate together by sharing the SlideTransition. I also fixed the Scaffold hit testing code to apply sub-widget transforms, so it works with Transformed nodes.
This commit is contained in:
@@ -80,6 +80,7 @@ class FeedFragment extends StatefulComponent {
|
||||
onItemDeleted = source.onItemDeleted;
|
||||
}
|
||||
|
||||
AnimationStatus _snackBarStatus = AnimationStatus.dismissed;
|
||||
bool _isShowingSnackBar = false;
|
||||
|
||||
EventDisposition _handleFitnessModeChange(FitnessMode value) {
|
||||
@@ -168,6 +169,7 @@ class FeedFragment extends StatefulComponent {
|
||||
setState(() {
|
||||
_undoItem = item;
|
||||
_isShowingSnackBar = true;
|
||||
_snackBarStatus = AnimationStatus.forward;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,13 +207,16 @@ class FeedFragment extends StatefulComponent {
|
||||
});
|
||||
}
|
||||
|
||||
Anchor _snackBarAnchor = new Anchor();
|
||||
Widget buildSnackBar() {
|
||||
if (!_isShowingSnackBar)
|
||||
if (_snackBarStatus == AnimationStatus.dismissed)
|
||||
return null;
|
||||
return new SnackBar(
|
||||
showing: _isShowingSnackBar,
|
||||
anchor: _snackBarAnchor,
|
||||
content: new Text("Item deleted."),
|
||||
actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)]
|
||||
actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)],
|
||||
onDismissed: () { setState(() { _snackBarStatus = AnimationStatus.dismissed; }); }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -225,10 +230,11 @@ class FeedFragment extends StatefulComponent {
|
||||
Widget buildFloatingActionButton() {
|
||||
switch (_fitnessMode) {
|
||||
case FitnessMode.feed:
|
||||
return new FloatingActionButton(
|
||||
child: new Icon(type: 'content/add', size: 24),
|
||||
onPressed: _handleActionButtonPressed
|
||||
);
|
||||
return _snackBarAnchor.build(
|
||||
new FloatingActionButton(
|
||||
child: new Icon(type: 'content/add', size: 24),
|
||||
onPressed: _handleActionButtonPressed
|
||||
));
|
||||
case FitnessMode.chart:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -247,11 +247,13 @@ class StockHome extends StatefulComponent {
|
||||
});
|
||||
}
|
||||
|
||||
Anchor _snackBarAnchor = new Anchor();
|
||||
Widget buildSnackBar() {
|
||||
if (_snackBarStatus == AnimationStatus.dismissed)
|
||||
return null;
|
||||
return new SnackBar(
|
||||
showing: _isSnackBarShowing,
|
||||
anchor: _snackBarAnchor,
|
||||
content: new Text("Stock purchased!"),
|
||||
actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)],
|
||||
onDismissed: () { setState(() { _snackBarStatus = AnimationStatus.dismissed; }); }
|
||||
@@ -266,11 +268,12 @@ class StockHome extends StatefulComponent {
|
||||
}
|
||||
|
||||
Widget buildFloatingActionButton() {
|
||||
return new FloatingActionButton(
|
||||
child: new Icon(type: 'content/add', size: 24),
|
||||
backgroundColor: colors.RedAccent[200],
|
||||
onPressed: _handleStockPurchased
|
||||
);
|
||||
return _snackBarAnchor.build(
|
||||
new FloatingActionButton(
|
||||
child: new Icon(type: 'content/add', size: 24),
|
||||
backgroundColor: colors.RedAccent[200],
|
||||
onPressed: _handleStockPurchased
|
||||
));
|
||||
}
|
||||
|
||||
void addMenuToOverlays(List<Widget> overlays) {
|
||||
|
||||
Reference in New Issue
Block a user