Flutter开发之——动画—Tween

2023-12-13 13:30
文章标签 开发 动画 flutter tween

本文主要是介绍Flutter开发之——动画—Tween,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一 概述

  • Tween动画,又叫补间动画
  • Tween有两个关键帧,begin起始帧,end结束帧,补间动画在begin和end之间插入补帧完成动画效果
  • 常见的Tween动画有:ColorTween、SizeTween、RectTween、IntTween、StepTween、ConstantTween、CurveTween

二 Tween

2.1 说明

  • Tween是将值变化的过程进行了封装(封装了begin起始值和end结束值)
  • 将之前通过setState刷新获取到的值转换为动画的值来完成显示

2.2 构造函数

Tween({this.begin,this.end,});

2.3 更换为Tween后对比

使用Tween之前
//定义变化量
double _size = 100;
//变化量作用对象
Container(height: _size,width: _size,color: Colors.blue,alignment: Alignment.center,child: Text('点我变大'),)
//变化量的修改		@overridevoid initState() {super.initState();setState(() {_size = 100+100*_controller.value;});}		
使用Tween之后
Animation<double> animation;//变化过程动画变量
//动画控制器
_controller =  AnimationController(vsync: this,lowerBound: 0,upperBound: 1,duration: Duration(milliseconds: 1000),)
//动画开始和结束值    
animation=Tween<double>(begin: 100,end: 300).animate(_controller);//作用对象Container(height: animation.value,width: animation.value,color: Colors.red,alignment: Alignment.center,child: Text("点我变大"),)

三 示例

3.1 将上节动画使用Tween替换之后(Tween用于int,float类型变换)

代码
 AnimationController _controller;Animation<double> _animation;@overridevoid initState() {super.initState();_controller =  AnimationController(vsync: this,lowerBound: 0,upperBound: 1,duration: Duration(milliseconds: 1000),)..addStatusListener((AnimationStatus status) {if(status == AnimationStatus.completed){_controller.reverse();}else if(status == AnimationStatus.dismissed){_controller.forward();}});animation=Tween<double>(begin: 100,end: 300).animate(_controller);}//作用对象Center(child: GestureDetector(onTap: (){_controller.forward();},child: Container(height: animation.value,width: animation.value,color: Colors.red,alignment: Alignment.center,child: Text("点我执行动画"),),),)@overridevoid dispose() {super.dispose();_controller.dispose();}       
效果图

3.2 ColorTween(ColorTween用于Color类型变换)

代码
//变量定义
AnimationController _controller;Animation<Color> animationColor;//动画监听@overridevoid initState() {super.initState();_controller =  AnimationController(vsync: this,lowerBound: 0,upperBound: 1,duration: Duration(milliseconds: 1000),)..addStatusListener((AnimationStatus status) {if(status == AnimationStatus.completed){_controller.reverse();}else if(status == AnimationStatus.dismissed){_controller.forward();}});animationColor=ColorTween(begin: Colors.red,end: Colors.blue).animate(_controller); }//作用对象Center(child: GestureDetector(onTap: (){_controller.forward();},child: Container(height: 200,width: 200,color: animationColor.value,alignment: Alignment.center,child: Text("点我执行动画"),),),)
效果图

这篇关于Flutter开发之——动画—Tween的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/488632

相关文章

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Spring Shell 命令行实现交互式Shell应用开发

《SpringShell命令行实现交互式Shell应用开发》本文主要介绍了SpringShell命令行实现交互式Shell应用开发,能够帮助开发者快速构建功能丰富的命令行应用程序,具有一定的参考价... 目录引言一、Spring Shell概述二、创建命令类三、命令参数处理四、命令分组与帮助系统五、自定义S

Python通过模块化开发优化代码的技巧分享

《Python通过模块化开发优化代码的技巧分享》模块化开发就是把代码拆成一个个“零件”,该封装封装,该拆分拆分,下面小编就来和大家简单聊聊python如何用模块化开发进行代码优化吧... 目录什么是模块化开发如何拆分代码改进版:拆分成模块让模块更强大:使用 __init__.py你一定会遇到的问题模www.

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

Flutter打包APK的几种方式小结

《Flutter打包APK的几种方式小结》Flutter打包不同于RN,Flutter可以在AndroidStudio里编写Flutter代码并最终打包为APK,本篇主要阐述涉及到的几种打包方式,通... 目录前言1. android原生打包APK方式2. Flutter通过原生工程打包方式3. Futte

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark