Skip to content

Commit

Permalink
Merge pull request #110 from freshtechtips/new-property
Browse files Browse the repository at this point in the history
Adds Animate.enabled
  • Loading branch information
gskinner committed Nov 20, 2023
2 parents 33e23b3 + 17fd3e1 commit afba6ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.2.1] - 2023-10-22
### Added
- A new property which is `enabled` to the `Animate` widget class

## [4.2.0] - 2023-06-19
### Added
- `FollowPathEffect`
Expand Down
19 changes: 16 additions & 3 deletions lib/src/animate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Animate extends StatefulWidget with AnimateManager<Animate> {
/// Creates an Animate instance that will manage a list of effects and apply
/// them to the specified child.
Animate({
Key? key,
super.key,
this.child = const SizedBox.shrink(),
List<Effect>? effects,
this.onInit,
Expand All @@ -119,9 +119,9 @@ class Animate extends StatefulWidget with AnimateManager<Animate> {
this.controller,
this.adapter,
this.target,
this.enabled = true,
}) : autoPlay = autoPlay ?? true,
delay = delay ?? Duration.zero,
super(key: key) {
delay = delay ?? Duration.zero {
warn(
autoPlay != false || onPlay == null,
'Animate.onPlay is not called when Animate.autoPlay=false',
Expand All @@ -143,6 +143,13 @@ class Animate extends StatefulWidget with AnimateManager<Animate> {
/// The widget to apply animated effects to.
final Widget child;

/// If you don't want to play the animation and just return the child
/// for some reasons and you don't want to create helper widget or function
/// or builder that help to achieve that without too duplication
/// then please pass false to [enabled] as a value to return the
/// child directly
final bool enabled;

/// Called immediately after the controller is fully initialized, before
/// the [Animate.delay] or the animation starts playing (see: [onPlay]).
/// This is not called if an external [controller] is provided.
Expand Down Expand Up @@ -368,6 +375,10 @@ class _AnimateState extends State<Animate> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
Widget child = widget.child, parent = child;

if (!widget.enabled) {
return child;
}
ReparentChildBuilder? reparent = Animate.reparentTypes[child.runtimeType];
if (reparent != null) child = (child as dynamic).child;
for (EffectEntry entry in widget._entries) {
Expand All @@ -391,6 +402,7 @@ extension AnimateWidgetExtensions on Widget {
AnimationController? controller,
Adapter? adapter,
double? target,
bool enabled = true,
}) =>
Animate(
key: key,
Expand All @@ -403,6 +415,7 @@ extension AnimateWidgetExtensions on Widget {
controller: controller,
adapter: adapter,
target: target,
enabled: enabled,
child: this,
);
}
Expand Down

0 comments on commit afba6ea

Please sign in to comment.