Last active
May 15, 2019 04:29
-
-
Save mono0926/f3d4a1dfeecfe9d4071605905e155fff to your computer and use it in GitHub Desktop.
AnimatedOpacityの、opacityがゼロになったらVisibilityのvisibleがfalseになる版(透明Widgetの無駄がほぼゼロになる) BetterFadeTransition(https://gist.github.com/mono0926/e6f4b2238e02fdf5beb761b911b38a1c )を内部で利用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:common/widgets/widgets.dart'; | |
import 'package:flutter/widgets.dart'; | |
class BetterAnimatedOpacity extends ImplicitlyAnimatedWidget { | |
const BetterAnimatedOpacity({ | |
Key key, | |
this.child, | |
@required this.opacity, | |
Curve curve = Curves.linear, | |
@required Duration duration, | |
}) : assert(opacity != null && opacity >= 0.0 && opacity <= 1.0), | |
super(key: key, curve: curve, duration: duration); | |
final Widget child; | |
final double opacity; | |
@override | |
_AnimatedOpacityState createState() => _AnimatedOpacityState(); | |
} | |
class _AnimatedOpacityState | |
extends ImplicitlyAnimatedWidgetState<BetterAnimatedOpacity> { | |
Tween<double> _opacity; | |
Animation<double> _opacityAnimation; | |
@override | |
void forEachTween(TweenVisitor visitor) { | |
_opacity = visitor( | |
_opacity, | |
widget.opacity, | |
(value) => Tween<double>(begin: value as double), | |
) as Tween<double>; | |
} | |
@override | |
void didUpdateTweens() { | |
_opacityAnimation = animation.drive(_opacity); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return BetterFadeTransition( | |
opacity: _opacityAnimation, | |
child: widget.child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment