From 1e093701b7e93314213e4fde2fb26ab40203ffc9 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 3 May 2016 23:49:35 -0700 Subject: [PATCH] Save some memory by only storing one copy of the animation object... (#3724) Turns out we were storing the same object in the base class and the subclass. For pretty much every AnimatedWidget subclass. --- .../lib/src/widgets/modal_barrier.dart | 4 +-- .../flutter/lib/src/widgets/transitions.dart | 28 ++++++++----------- .../widget/page_forward_transitions_test.dart | 4 +-- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/packages/flutter/lib/src/widgets/modal_barrier.dart b/packages/flutter/lib/src/widgets/modal_barrier.dart index 62c36ea5e2..a19a820d78 100644 --- a/packages/flutter/lib/src/widgets/modal_barrier.dart +++ b/packages/flutter/lib/src/widgets/modal_barrier.dart @@ -51,10 +51,10 @@ class AnimatedModalBarrier extends AnimatedWidget { Key key, Animation color, this.dismissable: true - }) : color = color, super(key: key, animation: color); + }) : super(key: key, animation: color); /// If non-null, fill the barrier with this color. - final Animation color; + Animation get color => animation; /// Whether touching the barrier will pop the current route off the [Navigator]. final bool dismissable; diff --git a/packages/flutter/lib/src/widgets/transitions.dart b/packages/flutter/lib/src/widgets/transitions.dart index cf83535bfe..2508218a14 100644 --- a/packages/flutter/lib/src/widgets/transitions.dart +++ b/packages/flutter/lib/src/widgets/transitions.dart @@ -88,13 +88,13 @@ class SlideTransition extends AnimatedWidget { Animation position, this.transformHitTests: true, this.child - }) : position = position, super(key: key, animation: position); + }) : super(key: key, animation: position); /// The animation that controls the position of the child. /// /// If the current value of the position animation is (dx, dy), the child will /// be translated horizontally by width * dx and vertically by height * dy. - final Animation position; + Animation get position => animation; /// Whether hit testing should be affected by the slide animation. /// @@ -128,15 +128,13 @@ class ScaleTransition extends AnimatedWidget { Animation scale, this.alignment: FractionalOffset.center, this.child - }) : scale = scale, super(key: key, animation: scale) { - assert(scale != null); - } + }) : super(key: key, animation: scale); /// The animation that controls the scale of the child. /// /// If the current value of the scale animation is v, the child will be /// painted v times its normal size. - final Animation scale; + Animation get scale => animation; /// The alignment of the origin of the coordainte system in which the scale /// takes place, relative to the size of the box. @@ -170,13 +168,13 @@ class RotationTransition extends AnimatedWidget { Key key, Animation turns, this.child - }) : turns = turns, super(key: key, animation: turns); + }) : super(key: key, animation: turns); /// The animation that controls the rotation of the child. /// /// If the current value of the turns animation is v, the child will be /// rotated v * 2 * pi radians before being painted. - final Animation turns; + Animation get turns => animation; /// The widget below this widget in the tree. final Widget child; @@ -206,7 +204,7 @@ class SizeTransition extends AnimatedWidget { Animation sizeFactor, this.axisAlignment: 0.5, this.child - }) : sizeFactor = sizeFactor, super(key: key, animation: sizeFactor) { + }) : super(key: key, animation: sizeFactor) { assert(axis != null); } @@ -216,7 +214,7 @@ class SizeTransition extends AnimatedWidget { /// The animation that controls the (clipped) size of the child. If the current value /// of sizeFactor is v then the width or height of the widget will be its intrinsic /// width or height multiplied by v. - final Animation sizeFactor; + Animation get sizeFactor => animation; /// How to align the child along the axis that sizeFactor is modifying. final double axisAlignment; @@ -251,7 +249,7 @@ class FadeTransition extends AnimatedWidget { Key key, Animation opacity, this.child - }) : opacity = opacity, super(key: key, animation: opacity); + }) : super(key: key, animation: opacity); /// The animation that controls the opacity of the child. /// @@ -259,7 +257,7 @@ class FadeTransition extends AnimatedWidget { /// painted with an opacity of v. For example, if v is 0.5, the child will be /// blended 50% with its background. Similarly, if v is 0.0, the child will be /// completely transparent. - final Animation opacity; + Animation get opacity => animation; /// The widget below this widget in the tree. final Widget child; @@ -296,12 +294,10 @@ class PositionedTransition extends AnimatedWidget { Key key, Animation rect, this.child - }) : rect = rect, super(key: key, animation: rect) { - assert(rect != null); - } + }) : super(key: key, animation: rect); /// The animation that controls the child's size and position. - final Animation rect; + Animation get rect => animation; /// The widget below this widget in the tree. final Widget child; diff --git a/packages/flutter/test/widget/page_forward_transitions_test.dart b/packages/flutter/test/widget/page_forward_transitions_test.dart index 491ba8a39e..ddbcce2be3 100644 --- a/packages/flutter/test/widget/page_forward_transitions_test.dart +++ b/packages/flutter/test/widget/page_forward_transitions_test.dart @@ -12,9 +12,7 @@ class TestTransition extends AnimatedWidget { this.childFirstHalf, this.childSecondHalf, Animation animation - }) : super(key: key, animation: animation) { - assert(animation != null); - } + }) : super(key: key, animation: animation); final Widget childFirstHalf; final Widget childSecondHalf;