Skip to content

Commit

Permalink
update to use states_rebuilder: ^1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GIfatahTH committed Jun 16, 2019
1 parent 28b820f commit c845fdb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"Tweens"
]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.1.3].
1. update to use states_rebuilder: ^1.3.1
2. Fiw typos

## [0.1.2].
1. update to use states_rebuilder: ^1.2.0
2. resetAnimationOnRebuild default to false.
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This library is an animation library for Flutter that:
* Allows you to declare all animation setup in your logic classes (BloCs) and animate you widgets.

In flutter animation can be classified:
* Implicit: such as AnimatedContaine, AnimatedPadding, AnimatedPositioned and AnimatedDefaultTextStyle.
* Implicit: such as AnimatedContainer, AnimatedPadding, AnimatedPositioned and AnimatedDefaultTextStyle.
* Explicit: Where you define AnimationController, Animation and Tween classes, and you should explicitly start, stop and listen to animation status.

Following the same fashion, the Animator package offers implicit-like and explicit-like animation
Expand Down Expand Up @@ -43,21 +43,21 @@ With `repeats` argument (5) you define the number of forward periods you want yo

In the `builder` argument (6) you put your widgets to be animated. The builder is a function with Animation argument.

If you want to animate many Tween, use `tweenMap` argument (7). Is is a Map of String type keys and Tween type values. In this case you have to use `builderMap` (8) insteat of `builder` (6).
If you want to animate many Tween, use `tweenMap` argument (7). Is is a Map of String type keys and Tween type values. In this case you have to use `builderMap` (8) instead of `builder` (6).

With `endAnimationListener` (10) argument you can define a VoidCallback to be executed when animation is finished. For example, it can be used to trigger another animation.

With `customListener` (11) argument you can define a Function to be called every time the animation value changes. The customListener is provided with an Animation object.

With `statusListener` (12) argument you can define a Function to be called every time the status of the animation chage. The customListener is provided with an AnimationStatus, AnimationSetup objectt.
With `statusListener` (12) argument you can define a Function to be called every time the status of the animation change. The customListener is provided with an AnimationStatus, AnimationSetup objects.

`animateOnRebuild` (13) controls whether the animation is automatically restarted when Animator widget is rebuilt. The default value is true.

If you want to reset your animation, such as changing your Tween or duration, and want the new setting to be reconsidered when the Animator widget is rebuilt, set the `resetAnimationOnRebuild` (14) argument to true. The default value is false.

`name` is a unique name of your Animator widget. It is used to rebuild this widget from your logic classes.

`blocs` argument is a list of your logic classes you want to rebuild this widget from. The logic class should extand `StatesRebuilder`of the states_rebuilder package.
`blocs` argument is a list of your logic classes you want to rebuild this widget from. The logic class should extend `StatesRebuilder`of the states_rebuilder package.

## Example of a single Tween animation:

Expand Down Expand Up @@ -159,10 +159,10 @@ addListeners({
bool reset: true
})
```
3- `changeAnimatioSetup`: to change any of the animation parameters. such as tween, duration, curve, cycles and repeats
3- `changeAnimationSetup`: to change any of the animation parameters. such as tween, duration, curve, cycles and repeats

```dart
changeAnimatioSetup({
changeAnimationSetup({
Tween<dynamic> tween,
Map<String, Tween<dynamic>> tweenMap,
bool resetTweenMap: false,
Expand All @@ -187,7 +187,7 @@ triggerAnimation({

5- `disposeAnimation()` : to remove listener, statusListener and dispose the animation controller.

## Implicet animation example:
## Implicit animation example:
```dart
import 'dart:math';
import 'package:flutter/material.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Body extends StatelessWidget {
),
),
Divider(),
Text('Widget is not animatted on rebuild'),
Text('Widget is not animated on rebuild'),
Animator(
name: "widget 2",
blocs: [mainBloc],
Expand Down
50 changes: 25 additions & 25 deletions lib/animator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AnimatorBloc {

VoidCallback _listenerV, _customListenerV;
Function(AnimationStatus) _statusListener;
Function(AnimationStatus) _repeatstatusListener;
Function(AnimationStatus) _repeatStatusListener;
TickerProvider _tickerProvider;
int _cycles;
int _repeats;
Expand All @@ -73,7 +73,7 @@ class AnimatorBloc {
if (_statusListener != null) {
animation?.removeStatusListener(_statusListener);
}
animation?.removeStatusListener(_repeatstatusListener);
animation?.removeStatusListener(_repeatStatusListener);

_statusListener = (status) {
listener(status, this);
Expand Down Expand Up @@ -196,7 +196,7 @@ class AnimatorBloc {

/// Change any of the animation parameters.
/// such as tween, duration, curve, cycles and repeats.
changeAnimatioSetup({
changeAnimationSetup({
Tween tween,
Map<String, Tween> tweenMap,
bool resetTweenMap = false,
Expand Down Expand Up @@ -247,9 +247,9 @@ class AnimatorBloc {

_addCycleStatusListener(
int cycles, bool dispose, Function(AnimatorBloc) endAnimationListener) {
animation.removeStatusListener(_repeatstatusListener);
animation.removeStatusListener(_repeatStatusListener);
if (cycles == 0) {
_repeatstatusListener = (AnimationStatus status) {
_repeatStatusListener = (AnimationStatus status) {
if (status == AnimationStatus.completed) {
controller.reverse();
}
Expand All @@ -258,11 +258,11 @@ class AnimatorBloc {
}
};
} else {
_repeatstatusListener = (AnimationStatus status) {
_repeatStatusListener = (AnimationStatus status) {
if (status == AnimationStatus.completed) {
cycles--;
if (cycles <= 0) {
animation.removeStatusListener(_repeatstatusListener);
animation.removeStatusListener(_repeatStatusListener);
if (dispose) disposeAnimation();
if (endAnimationListener != null) endAnimationListener(this);
return;
Expand All @@ -273,7 +273,7 @@ class AnimatorBloc {
if (status == AnimationStatus.dismissed) {
cycles--;
if (cycles <= 0) {
animation.removeStatusListener(_repeatstatusListener);
animation.removeStatusListener(_repeatStatusListener);
if (dispose) disposeAnimation();
if (endAnimationListener != null) endAnimationListener(this);
return;
Expand All @@ -283,25 +283,25 @@ class AnimatorBloc {
}
};
}
animation.addStatusListener(_repeatstatusListener);
animation.addStatusListener(_repeatStatusListener);
}

_addRepeatStatusListener(
int repeats, bool dispose, Function(AnimatorBloc) endAnimationListener) {
animation.removeStatusListener(_repeatstatusListener);
animation.removeStatusListener(_repeatStatusListener);
if (repeats == 0) {
_repeatstatusListener = (AnimationStatus status) {
_repeatStatusListener = (AnimationStatus status) {
if (status == AnimationStatus.completed) {
controller.reset();
controller.forward();
}
};
} else {
_repeatstatusListener = (AnimationStatus status) {
_repeatStatusListener = (AnimationStatus status) {
if (status == AnimationStatus.completed) {
repeats--;
if (repeats <= 0) {
animation.removeStatusListener(_repeatstatusListener);
animation.removeStatusListener(_repeatStatusListener);
if (dispose) disposeAnimation();

if (endAnimationListener != null) {
Expand All @@ -315,7 +315,7 @@ class AnimatorBloc {
}
};
}
animation.addStatusListener(_repeatstatusListener);
animation.addStatusListener(_repeatStatusListener);
}

/// Remove listener, statusListener and dispose the animation controller
Expand Down Expand Up @@ -359,7 +359,7 @@ class Animator extends StatefulWidget {
}
if (builder != null && builderMap != null) {
throw FlutterError(
'You have to define either buider or "builderMap" argument. you can\'t define both\n'
'You have to define either builder or "builderMap" argument. you can\'t define both\n'
' - Define the "builder" argument if you have one Tween\n'
' - Define the "builderMap" argument if you have many Tweens');
}
Expand All @@ -380,7 +380,7 @@ class Animator extends StatefulWidget {
///`tween` argument is used for one Tween animation.
final Tween tween;

///A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seco
///A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds
final Duration duration;

///An easing curve, i.e. a mapping of the unit interval to the unit interval.
Expand All @@ -398,7 +398,7 @@ class Animator extends StatefulWidget {
///Animation settings are defined by the tween, duration and curve argument.
final bool resetAnimationOnRebuild;

///Whether to statrt the animation when the Animator widget
///Whether to start the animation when the Animator widget
///is inserted into the tree.
final bool triggerOnInit;

Expand Down Expand Up @@ -453,7 +453,7 @@ class _AnimatorState extends State<Animator> {
return StateWithMixinBuilder(
key: UniqueKey(),
mixinWith: MixinWith.tickerProviderStateMixin,
tag: 'animattionWithAnimtor#2597442',
tag: 'animationWithAnimator#2597442',
blocs: [_animatorBloc],
initState: (_, __, ticker) {
_animatorBloc.widget = widget;
Expand Down Expand Up @@ -482,21 +482,21 @@ class _AnimatorBloc extends StatesRebuilder {
bool _hasBloc = false;
Animator widget;

initAnim(TickerProvider ticker, int hashcode) {
initAnim(TickerProvider ticker, int hashCode) {
_hasBloc = widget.blocs != null && widget.blocs.isNotEmpty;
if (_hasBloc) {
_initAnim(ticker, "animattionWithAnimtor#2597442",
_initAnim(ticker, "animationWithAnimator#2597442",
widget.triggerOnInit ?? false);

widget.blocs.forEach(
(b) {
if (b == null) return;
b.addToListeners(
tag: widget.name, listener: _listener, hashcode: "$hashcode");
tag: widget.name, listener: _listener, hashCode: "$hashCode");
},
);
} else {
_initAnim(ticker, "animattionWithAnimtor#2597442",
_initAnim(ticker, "animationWithAnimator#2597442",
widget.triggerOnInit ?? true);
}
}
Expand Down Expand Up @@ -538,16 +538,16 @@ class _AnimatorBloc extends StatesRebuilder {
// if (widget.resetAnimationOnRebuild) {
// _animationSetup?.disposeAnimation();
// if (_hasBloc) {
// _initAnim(ticker, "animattionWithAnimtor#2597442",
// _initAnim(ticker, "animationWithAnimator#2597442",
// widget.triggerOnInit ?? false);
// } else {
// _initAnim(ticker, "animattionWithAnimtor#2597442",
// _initAnim(ticker, "animationWithAnimator#2597442",
// widget.triggerOnInit ?? true);
// }
// }
}

dispose(int hashcode) {
dispose(int hashCode) {
if (widget.blocs != null) {
widget.blocs.forEach(
(b) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: animator
description: A Flutter library that makes animation easer. It allows for separation of animation setup from the User Interface.
version: 0.1.2
version: 0.1.3
authors: [MELLATI meftah <[email protected]>]
homepage: https://github.com/GIfatahTH/animator

Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
states_rebuilder: ^1.2.0
states_rebuilder: ^1.3.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit c845fdb

Please sign in to comment.