Animations in Flutter from Poznań Flutter Developer Group (PFDG)
- types of animations
- tween animations
- Flare
https://www.meetup.com/poznan-flutter-developers/
https://www.facebook.com/poznanflutter
2. Poznan Flutter Developer Group
Agenda
- Animation types
- Tween animations, physics-based animation
- Animated Container widget
- Animated CrossFade widget
- Hero animation
- Flare overview
- FlareActor, NimaActor
- Expressive animations
2
For animated version of this presentation
click HERE
3. Poznan Flutter Developer Group
Animation types
- Tween animations
animate value over time
- Physics-based animations
animate in response to user input/movement, animation which include real-world physics
- Animating widgets
help to simplify animations - single responsibility
3
Animations in Flutter ARE INDEPENDENT from widgets
they animate
4. Poznan Flutter Developer Group
Tween animations
- Short: in-between animations
- start value, end value
- curve [ function: transition over time ]
4
Tween<double>(
begin: 0.0,
end: 5.0,
)
Tween<Position>(
begin: Position(5.0, 10.0),
end: Position(10.0, 15.0),
)
10. Poznan Flutter Developer Group
Physics-based animations
10
simulation = ScrollSpringSimulation(
SpringDescription(
mass: 1.0,
stiffness: 1.0,
damping: 1.0,
),
0.0, // start value
1.0, // end value
0.0, // velocity
);
@override
Widget build(BuildContext context) {
return GestureDetector(
onPanStart: startDrag,
onPanUpdate: onDrag,
onPanEnd: endDrag,
child: CustomPaint( // canvas on which to draw during the
paint phase
painter: BoxPainter(
boxPosition: boxPosition,
boxPositionOnStart: boxPositionOnStart ?? boxPosition,
touchPoint: point,
),
child: Container(),
),
);
}
11. Poznan Flutter Developer Group
Physics-based animations
11
void onDrag(DragUpdateDetails details) {
setState(() {
point = (context.findRenderObject() as RenderBox)
.globalToLocal(details.globalPosition);
final dragVec = start.dy - point.dy;
final normDragVec = (dragVec / context.size.height).clamp(- 1.0, 1.0);
boxPosition = (boxPositionOnStart + normDragVec).clamp( 0.0, 1.0);
});
}
12. Poznan Flutter Developer Group
Physics-based animations
- RenderBox, RenderObject
- onPanStart(), onPanUpdate(), onPanEnd()
which correspond to startDrag(), onDrag(),
endDrag() [GestureDetector]
- context.findRenderObject() as RenderBox
- DragUpdateDetails, DragStartDetails etc.
-
12
13. Poznan Flutter Developer Group
Physics library
13
/// Simple one-dimensional physics simulations, such as springs, friction, and
/// gravity, for use in user interface animations.
///
/// To use, import `package:flutter/physics.dart`.
library physics;
export 'src/physics/clamped_simulation.dart' ;
export 'src/physics/friction_simulation.dart' ;
export 'src/physics/gravity_simulation.dart' ;
export 'src/physics/simulation.dart' ;
export 'src/physics/spring_simulation.dart' ;
export 'src/physics/tolerance.dart' ;
export 'src/physics/utils.dart' ;
19. Poznan Flutter Developer Group
19
AnimatedContainer
Main properties
of AnimatedContainer
widget:
- curve
[ function over time /
how the animation behaves]
- duration
[animation duration]
20. Poznan Flutter Developer Group
20
AnimatedContainer
Properties [of AnimatedContainer] that are null
are not animated. Its child and descendants are
not animated.
21. Poznan Flutter Developer Group
21
AnimatedContainer
We can also animate more properties automatically, like:
● aligment
● padding
● color
● foregroundDecoration
● constraints [BoxConstraints]
● margin
● transform [Matrix4]; transformation matrix to apply before painting the container
25. Poznan Flutter Developer Group
25
Hero animation
Main properties:
tag - identifies specific widget which needs to be
animated across consequent screens
Tag has to be unique in a widget tree!
35. Poznan Flutter Developer Group
35
NimaActor
Main properties:
filename - *.nma file location [String]
[e.g. ‘assets/anim/example.nma’]
animation - initial animation [String][Optional]
defined inside Nima