text
stringlengths
1
372
in the terminal window, or type the following shortcuts:
<topic_end>
<topic_start>
animation
well-designed animation makes a UI feel intuitive,
contributes to the look and feel of a polished app,
and improves the user experience.
flutter’s animation support makes it easy
to implement simple and complex animations.
the flutter SDK includes many material design widgets
that include standard motion effects,
and you can easily customize these effects
to personalize your app.
in react native, animated APIs are used to create animations.
in flutter, use the animation
class and the AnimationController class.
animation is an abstract class that understands its
current value and its state (completed or dismissed).
the AnimationController class lets you
play an animation forward or in reverse,
or stop animation and set the animation
to a specific value to customize the motion.
<topic_end>
<topic_start>
how do i add a simple fade-in animation?
in the react native example below, an animated component,
FadeInView is created using the animated API.
the initial opacity state, final state, and the
duration over which the transition occurs are defined.
the animation component is added inside the animated component,
the opacity state fadeAnim is mapped
to the opacity of the text component that we want to animate,
and then, start() is called to start the animation.
to create the same animation in flutter, create an
AnimationController object named controller
and specify the duration. by default, an AnimationController
linearly produces values that range from 0.0 to 1.0,
during a given duration. the animation controller generates a new value
whenever the device running your app is ready to display a new frame.
typically, this rate is around 60 values per second.
when defining an AnimationController,
you must pass in a vsync object.
the presence of vsync prevents offscreen
animations from consuming unnecessary resources.
you can use your stateful object as the vsync by adding
TickerProviderStateMixin to the class definition.
an AnimationController needs a TickerProvider,
which is configured using the vsync argument on the constructor.
a tween describes the interpolation between a
beginning and ending value or the mapping from an input
range to an output range. to use a tween object
with an animation, call the tween object’s animate()
method and pass it the animation object that you want to modify.
for this example, a FadeTransition
widget is used and the opacity property is
mapped to the animation object.
to start the animation, use controller.forward().
other operations can also be performed using the
controller such as fling() or repeat().
for this example, the FlutterLogo
widget is used inside the FadeTransition widget.
<code_start>
import 'package:flutter/material.dart';
void main() {
runApp(const center(child: LogoFade()));
}
class LogoFade extends StatefulWidget {
const LogoFade({super.key});
@override
State<LogoFade> createState() => _LogoFadeState();
}
class _LogoFadeState extends State<LogoFade>
with SingleTickerProviderStateMixin {
late animation<double> animation;
late AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const duration(milliseconds: 3000),
vsync: this,
);
final CurvedAnimation curve = CurvedAnimation(
parent: controller,
curve: Curves.easeIn,
);
animation = tween(begin: 0.0, end: 1.0).animate(curve);
controller.forward();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
widget build(BuildContext context) {
return FadeTransition(
opacity: animation,
child: const SizedBox(
height: 300,