Require that you pass transitions a performance.

This fixes #1103.
This commit is contained in:
Hixie
2015-09-14 15:02:45 -07:00
parent 01778c4895
commit e73bbd949e
16 changed files with 384 additions and 354 deletions

View File

@@ -251,13 +251,13 @@ class StockHome extends StatefulComponent {
});
}
Anchor _snackBarAnchor = new Anchor();
GlobalKey snackBarKey = new GlobalKey(label: 'snackbar');
Widget buildSnackBar() {
if (_snackBarStatus == AnimationStatus.dismissed)
return null;
return new SnackBar(
transitionKey: snackBarKey,
showing: _isSnackBarShowing,
anchor: _snackBarAnchor,
content: new Text("Stock purchased!"),
actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)],
onDismissed: () { setState(() { _snackBarStatus = AnimationStatus.dismissed; }); }
@@ -272,12 +272,14 @@ class StockHome extends StatefulComponent {
}
Widget buildFloatingActionButton() {
return _snackBarAnchor.build(
new FloatingActionButton(
return new TransitionProxy(
transitionKey: snackBarKey,
child: new FloatingActionButton(
child: new Icon(type: 'content/add', size: 24),
backgroundColor: Colors.redAccent[200],
onPressed: _handleStockPurchased
));
)
);
}
void addMenuToOverlays(List<Widget> overlays) {

View File

@@ -15,7 +15,7 @@ class Stocklist extends Component {
child: new ScrollableList<Stock>(
items: stocks,
itemExtent: StockRow.kHeight,
itemBuilder: (stock) => new StockRow(stock: stock)
itemBuilder: (Stock stock) => new StockRow(stock: stock)
)
);
}

View File

@@ -22,21 +22,28 @@ class ProgressIndicatorApp extends App {
reverseCurve: ease,
interval: new Interval(0.0, 0.9)
);
valueAnimation.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.dismissed || status == AnimationStatus.completed)
reverseValueAnimationDirection();
});
valueAnimation.play(valueAnimationDirection);
}
void handleTap() {
if (valueAnimation.isAnimating)
valueAnimation.stop();
else
valueAnimation.resume();
setState(() {
// valueAnimation.isAnimating is part of our build state
if (valueAnimation.isAnimating)
valueAnimation.stop();
else
valueAnimation.resume();
});
}
void reverseValueAnimationDirection() {
setState(() {
valueAnimationDirection = (valueAnimationDirection == Direction.forward)
? Direction.reverse
: Direction.forward;
});
valueAnimationDirection = (valueAnimationDirection == Direction.forward)
? Direction.reverse
: Direction.forward;
valueAnimation.play(valueAnimationDirection);
}
Widget buildIndicators() {
@@ -58,11 +65,12 @@ class ProgressIndicatorApp extends App {
width: 50.0,
height: 30.0,
child: new CircularProgressIndicator(value: valueAnimation.value)
)
),
new Text("${(valueAnimation.value * 100.0).toStringAsFixed(1)}%" + (valueAnimation.isAnimating ? '' : ' (paused)'))
];
return new Column(
indicators
.map((c) => new Container(child: c, margin: const EdgeDims.symmetric(vertical: 20.0)))
.map((c) => new Container(child: c, margin: const EdgeDims.symmetric(vertical: 15.0, horizontal: 20.0)))
.toList(),
justifyContent: FlexJustifyContent.center
);
@@ -76,10 +84,7 @@ class ProgressIndicatorApp extends App {
decoration: new BoxDecoration(backgroundColor: Theme.of(this).cardColor),
child: new BuilderTransition(
variables: [valueAnimation.variable],
direction: valueAnimationDirection,
performance: valueAnimation,
onDismissed: reverseValueAnimationDirection,
onCompleted: reverseValueAnimationDirection,
performance: valueAnimation.view,
builder: buildIndicators
)
)
@@ -94,10 +99,13 @@ class ProgressIndicatorApp extends App {
accentColor: Colors.redAccent[200]
),
child: new Title(
title: 'Cards',
title: 'Progress Indicators',
child: new Scaffold(
toolbar: new ToolBar(center: new Text('Progress Indicators')),
body: body
body: new DefaultTextStyle(
style: Theme.of(this).text.title,
child: body
)
)
)
)