(Profile image from: https://unsplash.com/photos/pAs4IM6OGWI)
Check out the article.
You keep seeing beautiful page transitions but you think to yourself those are too much work?
Fear no more, villains are here to save you!
When doing animations when a page transition occurs you'd usally define an AnimationController
in the initState()
and start it there. You'd also have to wrap your widgets in AnimatedWidgets
to react to the AnimationController
. Besides this being a lot of boilerplate code which clogs up you precious widgets, animating on exit isn't as trivial.
Using this library you just wrap your widget you'd like to be animated when a page transition occurs in a Villain
and everything is handled automatically.
dependencies:
flutter_villains: "^1.0.0"
Run packages get and import:
import 'package:flutter_villains/villain.dart';
Define animations to play when a page is opened.
Villain(
villainAnimation: VillainAnimation.fromBottom(
relativeOffset: 0.4,
from: Duration(milliseconds: 100),
to: Duration(seconds: 1),
),
animateExit: false,
secondaryVillainAnimation: VillainAnimation.fade(),
child: Divider(
color: Colors.black,
height: 32.0,
),
),
That's it. No TickerProvider
s, no AnimationController
s, no boilerplate, no worries.
Remember the StaggeredAnimation tutorial? This is using SequenceAnimation internally and there is therefore no need to specify durations as portions of a time-frame. It just works.
With this basic setup the Divider
fades in and moves up when a page transition occures (don't forget the VillainTransitionObserver
more on that under Code).
The animation you'd like to use is not premade? Make it yourself with a few lines of code!
static VillainAnimation fade(
{double fadeFrom = 0.0,
double fadeTo = 1.0,
Duration from = Duration.zero,
Duration to: _kMaterialRouteTransitionLength,
Curve curve: Curves.linear}) =>
VillainAnimation(
from: from,
curve: curve,
to: to,
animatable: Tween<double>(begin: fadeFrom, end: fadeTo),
animatedWidgetBuilder: (animation, child) {
return FadeTransition(
opacity: animation,
child: child,
);
});
Every VillainAnimation
needs an Animatable
(most of the time it's a Tween
) and an AnimatedWidget
. Everything else is handled automatically.
There are two way of playing your villains.
MaterialApp
return new MaterialApp(
navigatorObservers: [new VillainTransitionObserver()],
VillainController.playAllVillains(context);
You can play up to two animations per Villain
. You can always wrap Villains inside each other for infinite animations!
Villain(
villainAnimation: VillainAnimation.fromBottomToTop(0.4, to: Duration(milliseconds: 150)),
animateExit: false,
secondaryVillainAnimation: VillainAnimation.fade,
child: Text(
"Hi",
style: Theme.of(context).textTheme.body1,
),
),
Define whether the villain should play on entrance/ exit.
animateEntrance: true,
animateExit: true,
When using the VillainController
manually, it checks this bool to determine whether it should animate.
static Future playAllVillains(BuildContext context, {bool entrance = true})
Villains entering the page are decoupled from the page transition, meaning they can be as long as they want. On the other hand, if a villain leaves the page, the animation is driven by the page transition. This means:
Take a look at the example folder for three nice examples.
The villain framework takes care of:
In contrast to real world villains, these villains are very easy to handle.
Currenty there are no controllers implemented to play individual villains by themselves. If you'd like to have that implemented I opened an issue discussing it. Check it out!
Icon from https://icons8.com/
For help getting started with Flutter, view our online documentation.
For help on editing package code, view the documentation.
Add this to your package's pubspec.yaml file:
dependencies:
flutter_villains: ^1.1.2
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:flutter_villains/villain.dart';
import 'package:flutter_villains/villains/utils.dart';
import 'package:flutter_villains/villains/villains.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.2.0 | Dec 6, 2018 |
|
|
1.1.6 | Oct 17, 2018 |
|
|
1.1.5 | Oct 14, 2018 |
|
|
1.1.4 | Oct 14, 2018 |
|
|
1.1.3 | Oct 4, 2018 |
|
|
1.1.2 | Aug 29, 2018 |
|
|
1.1.1 | Jul 30, 2018 |
|
|
1.0.1 | Jul 10, 2018 |
|
|
1.0.0 | Jul 9, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
87
|
Health:
Code health derived from static analysis.
[more]
|
50
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
80
|
Overall:
Weighted score of the above.
[more]
|
74
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms:
Error(s) prevent platform classification:
Error(s) in lib/villains/villains.dart: 'VillainTransitionObserver.didStartUserGesture' ('() → void') isn't a valid override of 'NavigatorObserver.didStartUserGesture' ('(Route<dynamic>, Route<dynamic>) → void').
Fix lib/villains/villains.dart
. (-25.38 points)
Analysis of lib/villains/villains.dart
failed with 1 error, 1 hint:
line 375 col 3: 'VillainTransitionObserver.didStartUserGesture' ('() → void') isn't a valid override of 'NavigatorObserver.didStartUserGesture' ('(Route<dynamic>, Route<dynamic>) → void').
line 4 col 8: Don't import implementation files from another package.
Format lib/villain.dart
.
Run flutter format
to format lib/villain.dart
.
Format lib/villains/utils.dart
.
Run flutter format
to format lib/villains/utils.dart
.
Fix platform conflicts. (-20 points)
Error(s) prevent platform classification:
Error(s) in lib/villains/villains.dart: 'VillainTransitionObserver.didStartUserGesture' ('() → void') isn't a valid override of 'NavigatorObserver.didStartUserGesture' ('(Route<dynamic>, Route<dynamic>) → void').
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.20.1 <3.0.0 | ||
flutter | 0.0.0 | ||
flutter_sequence_animation | ^2.0.0 | 2.0.1 | 3.0.1 |
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |