AnimatedBuilder should have a child

Providing a pre-built child is more efficient because we don't need to rebuild
the child every tick of the animation.
This commit is contained in:
Adam Barth
2016-01-20 09:10:34 -08:00
parent 715af6ebe8
commit d25951c517
10 changed files with 51 additions and 44 deletions

View File

@@ -15,7 +15,7 @@ class PageSelectorDemo extends StatelessComponent {
CurvedAnimation animation = new CurvedAnimation(parent: selection.animation, curve: Curves.ease);
return new AnimatedBuilder(
animation: animation,
builder: (BuildContext context) {
builder: (BuildContext context, Widget child) {
Color background = selection.value == iconName ? _selectedColor.end : _selectedColor.begin;
if (selection.valueIsChanging) {
// Then the selection's performance is animating from previousValue to value.

View File

@@ -47,7 +47,7 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> {
controller.play(direction);
}
Widget buildIndicators(BuildContext context) {
Widget buildIndicators(BuildContext context, Widget child) {
List<Widget> indicators = <Widget>[
new SizedBox(
width: 200.0,

View File

@@ -41,7 +41,7 @@ class CardTransition extends StatelessComponent {
Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: animation,
builder: (BuildContext context) {
builder: (BuildContext context, Widget child) {
double currentScale = scale.evaluate(animation);
Matrix4 transform = new Matrix4.identity()
..translate(x.evaluate(animation))
@@ -53,7 +53,8 @@ class CardTransition extends StatelessComponent {
child: child
)
);
}
},
child: child
);
}
}