Last active
May 15, 2019 04:15
-
-
Save mono0926/e6f4b2238e02fdf5beb761b911b38a1c to your computer and use it in GitHub Desktop.
FadeTransitionの、opacityがゼロになったらVisibilityのvisibleがfalseになる版(透明Widgetの無駄がほぼゼロになる)
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:flutter/widgets.dart'; | |
class BetterFadeTransition extends AnimatedWidget { | |
const BetterFadeTransition({ | |
Key key, | |
@required this.child, | |
@required Animation<double> opacity, | |
this.alwaysIncludeSemantics = false, | |
}) : super( | |
key: key, | |
listenable: opacity, | |
); | |
final Widget child; | |
final bool alwaysIncludeSemantics; | |
@override | |
Widget build(BuildContext context) { | |
final animation = listenable as Animation<double>; | |
return Visibility( | |
visible: animation.value != 0, | |
child: FadeTransition( | |
opacity: animation, | |
child: child, | |
alwaysIncludeSemantics: alwaysIncludeSemantics, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment