Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Created May 17, 2020 20:08
Show Gist options
  • Save lukepighetti/867812a1fe9eccc59e56df9e42783634 to your computer and use it in GitHub Desktop.
Save lukepighetti/867812a1fe9eccc59e56df9e42783634 to your computer and use it in GitHub Desktop.
ImplicitlyAnimatedBuilder
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),
);
}
}
@lukepighetti
Copy link
Author

Don't use this, use TweenAnimationBuilder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment