Visitar URL original
Introduce and migrate to DualTransitionBuilder by goderbauer · Pull Request #160 · flutter/packages · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
self review
  • Loading branch information
goderbauer committed May 20, 2020
commit 05d5fcd92bb0692556268b36fe05e6e24f306943
28 changes: 8 additions & 20 deletions packages/animations/lib/src/dual_transition_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import 'package:flutter/widgets.dart';
/// `animation` and wrapping the provided `child`.
///
/// The `animation` provided to the builder always runs forward from 0.0 to 1.0.
/// The builder will be called whenever the [Animation.value] of `animation`
/// has changed.
typedef TransitionBuilder = Widget Function(
BuildContext context,
Animation<double> animation,
Expand Down Expand Up @@ -61,7 +59,7 @@ class DualTransitionBuilder extends StatefulWidget {
///
/// The `animation` provided to this builder is running forward from 0.0 to
/// 1.0 when [animation] runs _forward_. When [animation] runs in reverse,
/// the given animation is set to [kAlwaysCompleteAnimation].
/// the given `animation` is set to [kAlwaysCompleteAnimation].
///
/// See also:
///
Expand All @@ -76,7 +74,7 @@ class DualTransitionBuilder extends StatefulWidget {
///
/// The `animation` provided to this builder is running forward from 0.0 to
/// 1.0 when [animation] runs in _reverse_. When [animation] runs forward,
/// the given animation is set to [kAlwaysDismissedAnimation].
/// the given `animation` is set to [kAlwaysDismissedAnimation].
///
/// See also:
///
Expand All @@ -91,10 +89,10 @@ class DualTransitionBuilder extends StatefulWidget {
final Widget child;

@override
State<DualTransitionBuilder> createState() => _CompositeAnimationState();
State<DualTransitionBuilder> createState() => _DualTransitionBuilderState();
}

class _CompositeAnimationState extends State<DualTransitionBuilder> {
class _DualTransitionBuilderState extends State<DualTransitionBuilder> {
AnimationStatus _effectiveAnimationStatus;
final ProxyAnimation _forwardAnimation = ProxyAnimation();
final ProxyAnimation _reverseAnimation = ProxyAnimation();
Expand All @@ -121,20 +119,10 @@ class _CompositeAnimationState extends State<DualTransitionBuilder> {
@override
void didUpdateWidget(DualTransitionBuilder oldWidget) {
super.didUpdateWidget(oldWidget);
_updateAnimationListener(
oldWidget.animation,
widget.animation,
);
}

void _updateAnimationListener(
Animation<double> oldAnimation,
Animation<double> animation,
) {
if (oldAnimation != animation) {
oldAnimation.removeStatusListener(_animationListener);
animation.addStatusListener(_animationListener);
_animationListener(animation.status);
if (oldWidget.animation != widget.animation) {
oldWidget.animation.removeStatusListener(_animationListener);
widget.animation.addStatusListener(_animationListener);
_animationListener(widget.animation.status);
}
}

Expand Down