flutter villains
flexible and easy to use page transitions. view documentation
what are villains?
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.
installation
dependencies:
flutter_villains: "^1.0.0"
run packages get and import:
import 'package:flutter_villains/villain.dart';
assembling pages with style
define animations to play when a page is opened.
easy to use
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).
flexible
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.
code
there are two way of playing your villains.
- if you want them to automatically play when a page transition occurs (you probably want that) then add this to your
materialapp
return new materialapp(
navigatorobservers: [new villaintransitionobserver()],
- play villains in a given context manually.
villaincontroller.playallvillains(context);
secondary animation
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,
),
),
extras
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:
- the exit animation is always as long a the exit page transition
- setting the duration doesn’t change anything
examples
take a look at the example folder for three nice examples.
features:
the villain framework takes care of:
- managing page transition callbacks
- supplying animations
- providing premade common animations
in contrast to real world villains, these villains are very easy to handle.
controller
currently 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!
Comments are closed.