-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b81f7f9
Showing
76 changed files
with
4,936 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
build/ | ||
ios/.generated/ | ||
ios/Flutter/Generated.xcconfig | ||
ios/Runner/GeneratedPluginRegistrant.* | ||
|
||
.idea | ||
|
||
pubspec.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 8661d8aecd626f7f57ccbcb735553edc05a2e713 | ||
channel: stable | ||
|
||
project_type: package |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Flutter", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## [0.0.1] - initial release. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2019 The MELLATI Meftah. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,282 @@ | ||
# animator | ||
|
||
This library is an animation library for Flutter that: | ||
* makes animation as simple as the simplest widget in Flutter with the help of Animator widget, | ||
* 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. | ||
* 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 | ||
|
||
# Implicit-like animation: | ||
|
||
With one widget, `Animator`, you can do all the available animation in Flutter. | ||
|
||
```dart | ||
Animator({ | ||
Key key, | ||
Tween<dynamic> tween, // (1) // Default tween: Tween<double>(begin:0 end: 1) | ||
Duration duration: const Duration(milliseconds: 500), // (2) | ||
Curve curve: Curves.linear, // (3) | ||
int cycles, // (4) | ||
int repeats: 1, // (5) | ||
(Animation<dynamic>) → Widget builder, // (6) | ||
Map<String, Tween<dynamic>> tweenMap, () → void endAnimationListener, // (7) | ||
(Map<String, Animation<dynamic>>) → Widget builderMap, // (8) | ||
() → void endAnimationListener, // (10) | ||
}) | ||
``` | ||
|
||
To implement any type of animation with animator you have to define a `Tween` (1), `Duration` (2) and `Curve` (3). ` | ||
|
||
With `cycles` argument (4) you define the number of forward and backward periods you want your animation to perform before stopping. | ||
|
||
With `repeats` argument (5) you define the number of forward periods you want your animation to perform before stopping. | ||
|
||
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). | ||
|
||
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. | ||
|
||
## Example of a single Tween animation: | ||
|
||
```dart | ||
import 'package:flutter/material.dart'; | ||
import 'package:animator/animator.dart'; | ||
void main() => runApp(AnimatedLogo()); | ||
class AnimatedLogo extends StatelessWidget { | ||
Widget build(BuildContext context) { | ||
return Animator( | ||
tween: Tween<double>(begin: 0, end: 300), | ||
cycles: 0, | ||
builder: (anim) => Center( | ||
child: Container( | ||
margin: EdgeInsets.symmetric(vertical: 10), | ||
height: anim.value, | ||
width: anim.value, | ||
child: FlutterLogo(), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Example of a multi-tween animation: | ||
|
||
```dart | ||
import 'package:flutter/material.dart'; | ||
import 'package:animator/animator.dart'; | ||
void main() => runApp(AnimatedLogo()); | ||
class AnimatedLogo extends StatelessWidget { | ||
Widget build(BuildContext context) { | ||
return Animator( | ||
tweenMap: { | ||
"scaleAnim": Tween<double>(begin: 0, end: 300), | ||
"translateAnim": Tween<Offset>(begin: Offset.zero, end: Offset(2, 0)), | ||
}, | ||
cycles: 0, | ||
builderMap: (anim) => Center( | ||
child: FractionalTranslation( | ||
translation: anim["translateAnim"].value, | ||
child: Container( | ||
margin: EdgeInsets.symmetric(vertical: 10), | ||
height: anim["scaleAnim"].value, | ||
width: anim['scaleAnim'].value, | ||
child: FlutterLogo(), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
``` | ||
|
||
# Explicit-like animation: | ||
With implicit-like animation you can implement almost all the available animation type in Flutter. However if you want more control over your animation use Explicit-like animation. | ||
|
||
In any of your logic classes, instantiate the `AnimationSetup` and assign it to a variable. | ||
|
||
```dart | ||
AniamtionSetup({ | ||
Tween<dynamic> tween, | ||
Duration duration: const Duration(milliseconds: 500), | ||
Curve curve: Curves.linear, | ||
Map<String, Tween<dynamic>> tweenMap, | ||
}) | ||
``` | ||
|
||
You have five methods: | ||
|
||
1- `initAnimation` : to initialize animation by adding listener | ||
|
||
```dart | ||
initAnimation({ | ||
StatesRebuilder bloc, | ||
List<State<StatefulWidget>> states, // reference to widgets to be rebuild each frame. | ||
List<String> ids, // reference to widgets to be rebuild each frame. | ||
bool trigger: false, // Auto start animation if trigger is true | ||
int cycles, | ||
int repeats, | ||
bool dispose: false // Dispose animation after it is finished | ||
(AniamtionSetup) → dynamic customListener, // any custom animation listener | ||
() → void endAnimationListener, | ||
}) | ||
``` | ||
|
||
2- `addListners`: to aAdd listners you want to calls every time animation ticks. | ||
|
||
```dart | ||
addListners({ | ||
List<State<StatefulWidget>> states, | ||
List<String> ids, | ||
StatesRebuilder bloc, | ||
bool reset: true | ||
}) | ||
``` | ||
3- `changeAnimatioSetup`: to change any of the animation parameters. such as tween, duration, curve, cycles and repeats | ||
|
||
```dart | ||
changeAnimatioSetup({ | ||
Tween<dynamic> tween, | ||
Map<String, Tween<dynamic>> tweenMap, | ||
bool resetTweenMap: false, | ||
Duration duration, | ||
Curve curve, | ||
bool trigger: false, | ||
int cycles, | ||
int repeats, | ||
bool dispose: false, | ||
(AniamtionSetup) → dynamic customListener, | ||
() → void endAnimationListener | ||
}) | ||
``` | ||
4- `triggerAnimation` : to starts running this animation forwards (towards the end). | ||
```dart | ||
triggerAnimation({ | ||
int cycles, | ||
int repeats, | ||
bool dispose: false | ||
}) | ||
``` | ||
|
||
5- `disposeAnimation()` : to remove listener, statusListner and dispose the animation controller. | ||
|
||
## Implicet animation example: | ||
```dart | ||
import 'dart:math'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:animator/animator.dart'; | ||
import 'package:states_rebuilder/states_rebuilder.dart'; | ||
class MyBloc extends StatesRebuilder { | ||
final myAnimation = AniamtionSetup( | ||
tweenMap: { | ||
"opacityAnim": Tween<double>(begin: 0.5, end: 1), | ||
"rotationAnim": Tween<double>(begin: 0, end: 2 * pi), | ||
"translateAnim": Tween<Offset>(begin: Offset.zero, end: Offset(1, 0)), | ||
}, | ||
duration: Duration(seconds: 2), | ||
); | ||
init() { | ||
myAnimation.initAnimation( | ||
bloc: this, | ||
ids: ["OpacityWidget", "RotationWidget"], | ||
cycles: 3, | ||
endAnimationListener: () => print("animation finished"), | ||
); | ||
} | ||
} | ||
MyBloc myBloc; | ||
class FlutterAnimation extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return StateBuilder( | ||
initState: (_) => myBloc = MyBloc(), | ||
dispose: (_) => myBloc = null, | ||
builder: (_) => Scaffold( | ||
appBar: AppBar( | ||
title: Text("Flutter Animation"), | ||
), | ||
body: Padding( | ||
padding: EdgeInsets.all(20), | ||
child: MyHomePage(), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
class MyHomePage extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return StateBuilder( | ||
initState: (_) => myBloc.init(), | ||
dispose: (_) => myBloc.myAnimation.disposeAnimation(), | ||
stateID: 'myAnimation', | ||
blocs: [myBloc], | ||
builder: (_) => Center(child: MyAnimation()), | ||
); | ||
} | ||
} | ||
class MyAnimation extends StatelessWidget { | ||
final _flutterLog100 = | ||
FlutterLogo(size: 150, style: FlutterLogoStyle.horizontal); | ||
@override | ||
Widget build(BuildContext context) { | ||
return Column(children: [ | ||
RaisedButton( | ||
child: Text("Animate"), | ||
onPressed: () => myBloc.myAnimation.triggerAnimation(), | ||
), | ||
StateBuilder( | ||
key: Key("opacity"), | ||
stateID: "OpacityWidget", | ||
blocs: [myBloc], | ||
builder: (anim) => FadeTransition( | ||
opacity: myBloc.myAnimation.animationMap["opacityAnim"], | ||
child: FractionalTranslation( | ||
translation: myBloc.myAnimation.valueMap["translateAnim"], | ||
child: _flutterLog100, | ||
), | ||
), | ||
), | ||
StateBuilder( | ||
key: Key("rotation"), | ||
stateID: "RotationWidget", | ||
blocs: [myBloc], | ||
builder: (anim) { | ||
return Container( | ||
child: FractionalTranslation( | ||
translation: myBloc.myAnimation.valueMap["translateAnim"], | ||
child: Transform.rotate( | ||
angle: myBloc.myAnimation.valueMap['rotationAnim'], | ||
child: _flutterLog100, | ||
), | ||
), | ||
); | ||
}, | ||
) | ||
]); | ||
} | ||
} | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
23 changes: 23 additions & 0 deletions
23
android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.flutter.plugins; | ||
|
||
import io.flutter.plugin.common.PluginRegistry; | ||
|
||
/** | ||
* Generated file. Do not edit. | ||
*/ | ||
public final class GeneratedPluginRegistrant { | ||
public static void registerWith(PluginRegistry registry) { | ||
if (alreadyRegisteredWith(registry)) { | ||
return; | ||
} | ||
} | ||
|
||
private static boolean alreadyRegisteredWith(PluginRegistry registry) { | ||
final String key = GeneratedPluginRegistrant.class.getCanonicalName(); | ||
if (registry.hasPlugin(key)) { | ||
return true; | ||
} | ||
registry.registrarFor(key); | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" /> | ||
<excludeFolder url="file://$MODULE_DIR$/.idea" /> | ||
<excludeFolder url="file://$MODULE_DIR$/.pub" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Dart Packages" level="project" /> | ||
<orderEntry type="library" name="Dart SDK" level="project" /> | ||
<orderEntry type="library" name="Flutter Plugins" level="project" /> | ||
</component> | ||
</module> |
Oops, something went wrong.