Created
May 17, 2020 20:08
-
-
Save lukepighetti/867812a1fe9eccc59e56df9e42783634 to your computer and use it in GitHub Desktop.
ImplicitlyAnimatedBuilder
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/material.dart'; | |
/// An implicitly animated builder that tweens from 0.0 to 1.0 based on `isActive` property | |
class ImplicitlyAnimatedBuilder extends ImplicitlyAnimatedWidget { | |
ImplicitlyAnimatedBuilder({ | |
Key key, | |
@required Curve curve, | |
@required Duration duration, | |
@required this.isActive, | |
@required this.builder, | |
}) : super(key: key, curve: curve, duration: duration); | |
/// When active, tweens to 1.0. When inactive, tweens to 0.0. | |
final bool isActive; | |
final Widget Function(BuildContext, double) builder; | |
@override | |
ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget> createState() => | |
_ImplicitlyAnimatedBuilderState(); | |
} | |
class _ImplicitlyAnimatedBuilderState | |
extends AnimatedWidgetBaseState<ImplicitlyAnimatedBuilder> { | |
Tween<double> _value; | |
@override | |
Widget build(BuildContext context) { | |
return widget.builder(context, _value.evaluate(animation)); | |
} | |
@override | |
void forEachTween(visitor) { | |
_value = visitor( | |
_value, | |
widget.isActive ? 1.0 : 0.0, | |
(dynamic value) => Tween<double>(begin: value), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't use this, use TweenAnimationBuilder