当前位置:网站首页>[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)
[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)
2022-07-03 01:36:00 【Programmer community】
List of articles
- ◯、AnimatedWidget Component Introduction
- One 、 establish AnimatedWidget Animation components
- Two 、 Create animation controllers
- 3、 ... and 、 Create animation
- Four 、 Animation runs
- 5、 ... and 、 Complete code example
- 6、 ... and 、 Related resources
AnimatedWidget Animation usage process :
① establish AnimatedWidget Animation components
② Create animation controllers
③ Create animation
④ Animation runs
◯、AnimatedWidget Component Introduction
In the last blog 【Flutter】Animation Animation ( Flutter Basic animation process | Create animation controllers | Create animation | Set value listener | Set up state listeners | Use animation values in layout | Animation runs ) in , When using animation , You need to add a value listener to the animation , Whenever the animation value is updated , Will call back the listener , In the callback method of the listener , Need to call setState Method , Set the animation value to the component ;
The above operation is very tedious , Need to register listener , Get animation values , Then set the animation value to the component ;
Use AnimatedWidget Components , You can directly realize the above operations ;
AnimatedWidget Components Can greatly simplify Flutter The use of animation in , Don't use AnimatedWidget Words , You need to add listeners manually , And manually call in the listener setState Update animation ;
One 、 establish AnimatedWidget Animation components
AnimatedWidget The animation component encapsulates Animation Animated objects , The animation value can be calculated automatically , And automatically refresh the package in this AnimatedWidget Layout components in animation components ;
establish AnimatedWidget When animating components , Pass in Animation object ;
" AnimatedWidget Animation components " Code example : When the component is refreshed , Every refresh will call the build Method , Use here Text Component displays the status and value of the animation , And draw animated components Container , Container The width and height of the component is the animation value , As the animation value changes , The width and height of the component will increase ;
/// 1. Define animation components , The animation component is encapsulated in this component /// Use AnimatedWidget Quickly realize an animation class AnimatedApp extends AnimatedWidget{
/// Constructors AnimatedApp({
Key key, Animation<double> animation}) :super(key: key, listenable: animation); @override Widget build(BuildContext context) {
/// Get animation Animation<double> animation = listenable; return Column( children: [ Text(" Animation state : ${animation.status}", textDirection: TextDirection.ltr,), Text(" Animation values : ${animation.value.round()}", textDirection: TextDirection.ltr,), // The main component of the animation // Use animated values in layout components , In order to achieve the animation effect Container( /// Set the distance from the top 20 Pixels margin: EdgeInsets.only(top: 50), height: animation.value, width: animation.value, decoration: BoxDecoration(color: Colors.red), ), ], ); }}Two 、 Create animation controllers
AnimationController Constructor parameter description :
AnimationController( {
double? value, /// The initial value of the animation Duration? duration, /// Animation forward playback duration Duration? reverseDuration, /// Animation playback duration in reverse order String? debugLabel, /// Flags that identify animation during debugging double lowerBound: 0.0, /// Animation minimum double upperBound: 1.0, /// Animation max AnimationBehavior animationBehavior: AnimationBehavior.normal, /// Contextual TickerProvider , Used to prevent off screen animation from consuming unnecessary resources , /// Generally will StatefulWidget As vsync value required TickerProvider vsync} ) Among the above parameters , Just set up required TickerProvider vsync Parameters And Duration? duration Parameters can be ;
Create an animation controller code example :
/// 1. Initialize the animation controller animationController = AnimationController( // When the animation is drawn outside the screen , Reduce consumption vsync: this, // Animation duration 2 second duration: Duration(seconds: 3), );3、 ... and 、 Create animation
Here to create Tween Patch animation , Set initial values for animation
0
0
0 , End value
300
300
300 , The animation is executing
3
3
3 In seconds ( Animation duration specified in the animation controller ) , Automatically calculate the
0
0
0 ~
300
300
300 Animation values between ;
Create animation code examples :
/// 2 . structure Tween Patch animation , /// Set up animation controller AnimationController Animate the room /// The animation value is the width and height of the square component animation = Tween<double>( begin: 0, end: 300 ).animate(animationController)Four 、 Animation runs
monitor GestureDetector Of onTap Click event , After clicking this component , call animationController.forward() Method , Run the animation ;
Code example :
GestureDetector( // 5 . Click the button to start the animation onTap: (){
/// Button click event /// First initialize the animation animationController.reset(); /// Executing animation forward , That is, from the initial value to the end value animationController.forward(); }, child: Container( alignment: Alignment.center, color: Colors.green, height: 50, child: Text( // Show text " Animation start ", /// Text direction : From left to right textDirection: TextDirection.ltr, ), ), ),5、 ... and 、 Complete code example
Complete code example :
import 'package:flutter/material.dart';void main() {
runApp(AnimationApp());}/// 1. Define animation components , The animation component is encapsulated in this component /// Use AnimatedWidget Quickly realize an animation class AnimatedApp extends AnimatedWidget{
/// Constructors AnimatedApp({
Key key, Animation<double> animation}) :super(key: key, listenable: animation); @override Widget build(BuildContext context) {
/// Get animation Animation<double> animation = listenable; return Column( children: [ Text(" Animation state : ${animation.status}", textDirection: TextDirection.ltr,), Text(" Animation values : ${animation.value.round()}", textDirection: TextDirection.ltr,), // The main component of the animation // Use animated values in layout components , In order to achieve the animation effect Container( /// Set the distance from the top 20 Pixels margin: EdgeInsets.only(top: 50), height: animation.value, width: animation.value, decoration: BoxDecoration(color: Colors.red), ), ], ); }}/// Animation example main interface component /// This component is stateful , So we need to define StatefulWidget Components class AnimationApp extends StatefulWidget{
@override _AnimationAppState createState() => _AnimationAppState();}/// by StatefulWidget Component creation State class /// Every StatefulWidget Need a matching State class class _AnimationAppState extends State<AnimationApp> with SingleTickerProviderStateMixin{
/// Animation class Animation<double> animation; /// Animation controller AnimationController animationController; @override void initState() {
super.initState(); /// 2. Initialize the animation controller animationController = AnimationController( // When the animation is drawn outside the screen , Reduce consumption vsync: this, // Animation duration 2 second duration: Duration(seconds: 3), ); /// 3 . structure Tween Patch animation , /// Set up animation controller AnimationController Animate the room /// The animation value is the width and height of the square component animation = Tween<double>( begin: 0, end: 300 ).animate(animationController); } /// The method and initState Corresponding @override void dispose() {
/// Release the animation controller animationController.dispose(); super.dispose(); } @override Widget build(BuildContext context) {
return Container( /// Set the distance from the top 20 Pixels margin: EdgeInsets.only(top: 100), child: Column( children: [ GestureDetector( // 5 . Click the button to start the animation onTap: (){
/// Button click event /// First initialize the animation animationController.reset(); /// Executing animation forward , That is, from the initial value to the end value animationController.forward(); }, child: Container( alignment: Alignment.center, color: Colors.green, height: 50, child: Text( // Show text " Animation start ", /// Text direction : From left to right textDirection: TextDirection.ltr, ), ), ), // The main component of the animation // 4 . Create animation components , Pass in animated objects animation AnimatedApp(animation: animation,), ], ), ); }}Running effect :

6、 ... and 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Plug in download address : https://pub.dev/packages
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
- GitHub Upper Flutter Open source examples : https://download.csdn.net/download/han1202012/15989510
- Flutter Practical e-books : https://book.flutterchina.club/chapter1/
Important topics :
- Flutter Animation reference documentation : https://flutterchina.club/animations/
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_animation ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/16184761 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Kivy tutorial - example of using Matplotlib in Kivy app
- 【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
- VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
- MySQL foundation 04 MySQL architecture
- LDC Build Shared Library
- Summary of interval knowledge
- Mathematical knowledge: divisible number inclusion exclusion principle
- Machine learning terminology
- [shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
猜你喜欢

C#应用程序界面开发基础——窗体控制(2)——MDI窗体
![[data mining] task 6: DBSCAN clustering](/img/af/ad7aa523b09884eee967c6773a613f.png)
[data mining] task 6: DBSCAN clustering
![[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)](/img/3c/93ef853784d4e7cef63f30be0b0bf2.jpg)
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)

Basis of information entropy

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9

LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7

Arduino dy-sv17f automatic voice broadcast

Top ten regular spot trading platforms 2022

Steps to obtain SSL certificate private key private key file
![[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait](/img/c6/9aee30cb935b203c7c62b12c822085.jpg)
[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait
随机推荐
[data mining] task 6: DBSCAN clustering
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
Learn the five skills you need to master in cloud computing application development
dotConnect for PostgreSQL数据提供程序
Is there a handling charge for spot gold investment
C语言课程信息管理系统
海量数据冷热分离方案与实践
Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
Mathematical knowledge: divisible number inclusion exclusion principle
[interview question] 1369 when can't I use arrow function?
JDBC courses
Canvas drawing -- bingdd
C application interface development foundation - form control (3) - file control
Machine learning terminology
LDC Build Shared Library
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio
CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr