diff --git a/examples/material_gallery/lib/demo/progress_indicator_demo.dart b/examples/material_gallery/lib/demo/progress_indicator_demo.dart index 1b5337d27d..d6701b99f0 100644 --- a/examples/material_gallery/lib/demo/progress_indicator_demo.dart +++ b/examples/material_gallery/lib/demo/progress_indicator_demo.dart @@ -14,39 +14,44 @@ class _ProgressIndicatorDemoState extends State { super.initState(); controller = new AnimationController( duration: const Duration(milliseconds: 1500) - )..play(AnimationDirection.forward); + )..forward(); animation = new CurvedAnimation( parent: controller, curve: new Interval(0.0, 0.9, curve: Curves.ease), reverseCurve: Curves.ease )..addStatusListener((AnimationStatus status) { - if (status == AnimationStatus.dismissed || status == AnimationStatus.completed) - reverseValueAnimationDirection(); + if (status == AnimationStatus.dismissed) + controller.forward(); + else if (status == AnimationStatus.completed) + controller.reverse(); }); } Animation animation; AnimationController controller; - void handleTap() { + void _handleTap() { setState(() { // valueAnimation.isAnimating is part of our build state - if (controller.isAnimating) + if (controller.isAnimating) { controller.stop(); - else - controller.resume(); + } else { + switch (controller.status) { + case AnimationStatus.dismissed: + case AnimationStatus.forward: + controller.forward(); + break; + case AnimationStatus.reverse: + case AnimationStatus.completed: + controller.reverse(); + break; + } + } }); } - void reverseValueAnimationDirection() { - AnimationDirection direction = (controller.direction == AnimationDirection.forward) - ? AnimationDirection.reverse - : AnimationDirection.forward; - controller.play(direction); - } - - Widget buildIndicators(BuildContext context, Widget child) { + Widget _buildIndicators(BuildContext context, Widget child) { List indicators = [ new SizedBox( width: 200.0, @@ -82,13 +87,13 @@ class _ProgressIndicatorDemoState extends State { body: new DefaultTextStyle( style: Theme.of(context).text.title, child: new GestureDetector( - onTap: handleTap, + onTap: _handleTap, behavior: HitTestBehavior.opaque, child: new Container( padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0), child: new AnimatedBuilder( animation: animation, - builder: buildIndicators + builder: _buildIndicators ) ) ) diff --git a/packages/flutter/lib/src/animation/animation.dart b/packages/flutter/lib/src/animation/animation.dart index 1e89f48edb..cc2deb1b4d 100644 --- a/packages/flutter/lib/src/animation/animation.dart +++ b/packages/flutter/lib/src/animation/animation.dart @@ -4,15 +4,6 @@ import 'dart:ui' show Color, Size, Rect, VoidCallback; -/// The direction in which an animation is running. -enum AnimationDirection { - /// The animation is running from beginning to end. - forward, - - /// The animation is running backwards, from end to beginning. - reverse -} - /// The status of an animation enum AnimationStatus { /// The animation is stopped at the beginning @@ -62,9 +53,6 @@ abstract class Animation { /// The current status of this animation. AnimationStatus get status; - /// The current direction of the animation. - AnimationDirection get direction; - /// The current value of the animation. T get value; @@ -79,7 +67,6 @@ abstract class Animation { } String toStringDetails() { assert(status != null); - assert(direction != null); String icon; switch (status) { case AnimationStatus.forward: @@ -89,24 +76,10 @@ abstract class Animation { icon = '\u25C0'; // < break; case AnimationStatus.completed: - switch (direction) { - case AnimationDirection.forward: - icon = '\u23ED'; // >>| - break; - case AnimationDirection.reverse: - icon = '\u29CF'; // <| - break; - } + icon = '\u23ED'; // >>| break; case AnimationStatus.dismissed: - switch (direction) { - case AnimationDirection.forward: - icon = '\u29D0'; // |> - break; - case AnimationDirection.reverse: - icon = '\u23EE'; // |<< - break; - } + icon = '\u23EE'; // |<< break; } assert(icon != null); diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index db0461095d..52f7d56e27 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -13,6 +13,15 @@ import 'curves.dart'; import 'forces.dart'; import 'listener_helpers.dart'; +/// The direction in which an animation is running. +enum _AnimationDirection { + /// The animation is running from beginning to end. + forward, + + /// The animation is running backwards, from end to beginning. + reverse +} + /// A controller for an animation. /// /// An animation controller can drive an animation forward or backward and can @@ -79,9 +88,6 @@ class AnimationController extends Animation /// The length of time this animation should last. Duration duration; - AnimationDirection get direction => _direction; - AnimationDirection _direction = AnimationDirection.forward; - Ticker _ticker; Simulation _simulation; @@ -106,31 +112,28 @@ class AnimationController extends Animation /// Whether this animation is currently animating in either the forward or reverse direction. bool get isAnimating => _ticker.isTicking; + _AnimationDirection _direction; + AnimationStatus get status { if (!isAnimating && value == upperBound) return AnimationStatus.completed; if (!isAnimating && value == lowerBound) return AnimationStatus.dismissed; - return _direction == AnimationDirection.forward ? + return _direction == _AnimationDirection.forward ? AnimationStatus.forward : AnimationStatus.reverse; } /// Starts running this animation forwards (towards the end). - Future forward() => play(AnimationDirection.forward); - - /// Starts running this animation in reverse (towards the beginning). - Future reverse() => play(AnimationDirection.reverse); - - /// Starts running this animation in the given direction. - Future play(AnimationDirection direction) { - _direction = direction; - return resume(); + Future forward() { + _direction = _AnimationDirection.forward; + return animateTo(upperBound); } - /// Resumes this animation in the most recent direction. - Future resume() { - return animateTo(_direction == AnimationDirection.forward ? upperBound : lowerBound); + /// Starts running this animation in reverse (towards the beginning). + Future reverse() { + _direction = _AnimationDirection.reverse; + return animateTo(lowerBound); } /// Drives the animation from its current value to target. @@ -166,7 +169,7 @@ class AnimationController extends Animation /// animation will complete, otherwise it will dismiss. Future fling({ double velocity: 1.0, Force force }) { force ??= kDefaultSpringForce; - _direction = velocity < 0.0 ? AnimationDirection.reverse : AnimationDirection.forward; + _direction = velocity < 0.0 ? _AnimationDirection.reverse : _AnimationDirection.forward; return animateWith(force.release(value, velocity)); } diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index 08e269eb68..5cd46c2bc2 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -16,7 +16,6 @@ class _AlwaysCompleteAnimation extends Animation { void addStatusListener(AnimationStatusListener listener) { } void removeStatusListener(AnimationStatusListener listener) { } AnimationStatus get status => AnimationStatus.completed; - AnimationDirection get direction => AnimationDirection.forward; double get value => 1.0; } @@ -35,7 +34,6 @@ class _AlwaysDismissedAnimation extends Animation { void addStatusListener(AnimationStatusListener listener) { } void removeStatusListener(AnimationStatusListener listener) { } AnimationStatus get status => AnimationStatus.dismissed; - AnimationDirection get direction => AnimationDirection.forward; double get value => 0.0; } @@ -57,7 +55,6 @@ class AlwaysStoppedAnimation extends Animation { void addStatusListener(AnimationStatusListener listener) { } void removeStatusListener(AnimationStatusListener listener) { } AnimationStatus get status => AnimationStatus.forward; - AnimationDirection get direction => AnimationDirection.forward; } /// Implements most of the [Animation] interface, by deferring its behavior to a @@ -77,7 +74,6 @@ abstract class AnimationWithParentMixin { void removeStatusListener(AnimationStatusListener listener) => parent.removeStatusListener(listener); AnimationStatus get status => parent.status; - AnimationDirection get direction => parent.direction; } /// An animation that is a proxy for another animation. @@ -92,13 +88,11 @@ class ProxyAnimation extends Animation _parent = animation; if (_parent == null) { _status = AnimationStatus.dismissed; - _direction = AnimationDirection.forward; _value = 0.0; } } AnimationStatus _status; - AnimationDirection _direction; double _value; /// The animation whose value this animation will proxy. @@ -112,7 +106,6 @@ class ProxyAnimation extends Animation return; if (_parent != null) { _status = _parent.status; - _direction = _parent.direction; _value = _parent.value; if (isListening) didStopListening(); @@ -126,7 +119,6 @@ class ProxyAnimation extends Animation if (_status != _parent.status) notifyStatusListeners(_parent.status); _status = null; - _direction = null; _value = null; } } @@ -146,7 +138,6 @@ class ProxyAnimation extends Animation } AnimationStatus get status => _parent != null ? _parent.status : _status; - AnimationDirection get direction => _parent != null ? _parent.direction : _direction; double get value => _parent != null ? _parent.value : _value; } @@ -186,7 +177,6 @@ class ReverseAnimation extends Animation } AnimationStatus get status => _reverseStatus(parent.status); - AnimationDirection get direction => _reverseDirection(parent.direction); double get value => 1.0 - parent.value; AnimationStatus _reverseStatus(AnimationStatus status) { @@ -197,13 +187,6 @@ class ReverseAnimation extends Animation case AnimationStatus.dismissed: return AnimationStatus.completed; } } - - AnimationDirection _reverseDirection(AnimationDirection direction) { - switch (direction) { - case AnimationDirection.forward: return AnimationDirection.reverse; - case AnimationDirection.reverse: return AnimationDirection.forward; - } - } } /// An animation that applies a curve to another animation. @@ -238,7 +221,7 @@ class CurvedAnimation extends Animation with AnimationWithParentMixin with AnimationWithParentMixin } AnimationStatus get status => _currentTrain.status; - AnimationDirection get direction => _currentTrain.direction; double _lastValue; void _valueChangeHandler() { diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index b7a29bbd3b..e636a81662 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -51,7 +51,7 @@ class _BottomSheetState extends State { return renderBox.size.height; } - bool get _dismissUnderway => config.animationController.direction == AnimationDirection.reverse; + bool get _dismissUnderway => config.animationController.status == AnimationStatus.reverse; void _handleDragUpdate(double delta) { if (_dismissUnderway) diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index cb98d4eeef..056bd82a71 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -810,7 +810,6 @@ class _TabBarViewState extends PageableListState implements TabBarSe TabBarSelectionState _selection; List _items; - AnimationDirection _scrollDirection = AnimationDirection.forward; int get _tabCount => config.children.length; @@ -907,16 +906,11 @@ class _TabBarViewState extends PageableListState implements TabBarSe if (selectedIndex < previousSelectedIndex) { _updateItemsFromChildren(selectedIndex, previousSelectedIndex); - _scrollDirection = AnimationDirection.reverse; + scrollTo(1.0 - animation.value); } else { _updateItemsFromChildren(previousSelectedIndex, selectedIndex); - _scrollDirection = AnimationDirection.forward; - } - - if (_scrollDirection == AnimationDirection.forward) scrollTo(animation.value); - else - scrollTo(1.0 - animation.value); + } } void dispatchOnScroll() { diff --git a/packages/flutter/lib/src/material/toggleable.dart b/packages/flutter/lib/src/material/toggleable.dart index 6baf3f4f4a..b48cd52ce0 100644 --- a/packages/flutter/lib/src/material/toggleable.dart +++ b/packages/flutter/lib/src/material/toggleable.dart @@ -66,7 +66,10 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic _position ..curve = Curves.easeIn ..reverseCurve = Curves.easeOut; - _positionController.play(value ? AnimationDirection.forward : AnimationDirection.reverse); + if (value) + _positionController.forward(); + else + _positionController.reverse(); } Color get activeColor => _activeColor; diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index 7081d6bc5f..8f13cdc36e 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -456,7 +456,8 @@ class HeroController extends NavigatorObserver { void _addHeroToOverlay(Widget hero, Object tag, OverlayState overlay) { OverlayEntry entry = new OverlayEntry(builder: (_) => hero); - if (_animation.direction == AnimationDirection.forward) + assert(_animation.status != AnimationStatus.dismissed && _animation.status != AnimationStatus.completed); + if (_animation.status == AnimationStatus.forward) _to.insertHeroOverlayEntry(entry, tag, overlay); else _from.insertHeroOverlayEntry(entry, tag, overlay);