当前位置:网站首页>Flutter怎么实现不同缩放动画效果
Flutter怎么实现不同缩放动画效果
2022-06-23 03:42:00 【亿速云】
Flutter怎么实现不同缩放动画效果
本篇内容主要讲解“Flutter怎么实现不同缩放动画效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Flutter怎么实现不同缩放动画效果”吧!
需求背景
组件缩放可以向着一个方向进行缩放,放大列表中某一个Cell期望它是向后进行放大而非组件中心点开始缩放。具体效果如下图所示:

可缩放组件介绍
ScaleTransition
ScaleTransition具体实现如下代码,设置AnimationController控制器若需要增加数值操作可以再增加Animate再调用forward方法执行。
PS:动画实现在以前文章中有介绍过
动画控制器_scaleAnimationController = AnimationController( vsync: this, duration: Duration(milliseconds: 3000),);scale = Tween(begin: 1.0, end: 1.29).animate(_scaleAnimationController);ScaleTransition( scale: scale, alignment: Alignment.centerLeft, child: Container( margin: EdgeInsets.all(50), color: Colors.yellow, height: 200, width: 100, ),)_scaleAnimationController.forward();
如果希望修改缩放方向,可以为ScaleTransition添加alignment配置。例如centerLeft表示组件靠左向右缩放。
ScaleTransition( scale: scale, alignment: Alignment.centerLeft, child: Container( margin: EdgeInsets.all(50), color: Colors.yellow, height: 200, width: 100, ),)
如图所示默认缩放是以组件中心点进行缩放效果,设置alignment则向着相反位置进行缩放。

但ScaleTransition并不能满足需求功能,无法做到向着一个方向进行缩放动画。
SizeTransition
SizeTransition是以更改子组件尺寸实现动画效果,支持垂直或水平方向动画。
AnimationController _animationController = AnimationController(vsync: this, duration: Duration(seconds: 1));_animationController.value = 1.0;Animation<double> _animation = CurvedAnimation( parent: _animationController, curve: Curves.fastLinearToSlowEaseIn);SizeTransition( sizeFactor: _animation, axis: Axis.horizontal, child: Container( color: Colors.blue, height: 100, width: 100, alignment: Alignment.center, child: Text("SizeTransition"), ),)
但在需求要求上还是不满足期望的结果,SizeTransition更适用在实现展开或是飞入的动画效果。
AnimatedSize
AnimatedSize是自带动画效果的组件,修改组件尺寸大小就能够执行缩放动画。
GestureDetector( child: AnimatedSize( duration: Duration(seconds: 2), child: Container( color: Colors.red, width: 100, height: height, alignment: Alignment.center, child: Container( height: 50, width: 50, color: Colors.yellow, child: Text("AnimatedSize"), ), ), ), onTap: () { height = 150; width = 150; setState(() {}); },),
但AnimatedSize的问题在于它只作用于自身,若子布局设置了自身的尺寸就不会随着父组件大小而变化。
AnimatedBuilder
AnimatedBuilder主要结合Transform.scale组件设置alignment为Alignment.centerLeft即可对组件实现向右缩放动画。
AnimationController _scaleAnimationController = AnimationController( vsync: this, duration: Duration(milliseconds: 3000),);Animation<double> scale = Tween(begin: 1.0, end: 1.29).animate(_scaleAnimationController); AnimatedBuilder( animation: scale, builder: (context, widget) { return Transform.scale( alignment: Alignment.centerLeft, scale: scale.value, child: widget, ); }, child: GestureDetector( child: Container( margin: EdgeInsets.only(left: 15, right: 15), color: Colors.blue, width: 100, height: 50, child: Text("AnimatedBuilder"), ), onTap: (){ _scaleAnimationController.forward(); }, ),);
AnimatedBuilder方式实现缩放需要为组件缩放预留好足够空间进行缩放放大操作,避免组件缩放后与其他组件出现重叠现象。
到此,相信大家对“Flutter怎么实现不同缩放动画效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
边栏推荐
- Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
- 关于sql语句的问题
- Easygbs service is killed because the user redis is infected with the mining virus process. How to solve and prevent it?
- Firewall and IP security policy configuration
- 【二分】leetcode1011. Capacity To Ship Packages Within D Days
- 【LeetCode】两数之和II
- 聊聊内存模型和内存序
- node+express如何操作cookie
- The new version of Kali switches the highest account
- 【owt】owt-client-native-p2p-e2e-test vs2017构建 3 : 无 测试单元对比, 手动生成vs项目
猜你喜欢

1058 multiple choice questions (20 points)

LRU cache

Efficient remote office experience | community essay solicitation
![[greed] leetcode991 Broken Calculator](/img/6e/ce552b55899c6e8d3c37f524f99f82.png)
[greed] leetcode991 Broken Calculator

Google Earth engine (GEE) - long time series monthly VCI data extraction, analysis and area calculation (Mexico as an example)

AI 视频云 VS 窄带高清,谁是视频时代的宠儿

JS Part 4

1-1VMware介绍

基于HAProxy实现网页动静分离

选择排序法
随机推荐
【owt】owt-client-native-p2p-e2e-test vs2017构建 3 : 无 测试单元对比, 手动生成vs项目
APM 工具 SkyWalking 是什么
怎样能在小程序中实现视频通话及互动直播功能?
冒泡排序法
Troubleshooting and resolution of asydss virtual live broadcast status synchronization and service downtime
如何处理大体积 XLSX/CSV/TXT 文件?
[binary tree] 993 Cousins in Binary Tree
The MIUI 13 development version of Xiaomi mobile phone blocks the chrome application and cannot be opened after installation
Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)
Detailed discussion on modular architecture design of MCU firmware
What is the difference between comparator and comparable?
新版kali切换最高账户
The power of code refactoring: how to measure the success of refactoring
Preliminary sequencing problem
SwiftUI 组件大全之使用 ScrollView 和 GeometryReader 创建动画 3D卡片 滚动效果
[Zeng shuge's laser slam notes] gmapping filter based slam
Firewall and IP security policy configuration
Apicloud native module, H5 module and multi terminal component tutorial
[metauniverse 7ai rope skipping] how is this app light application realized? What are the application scenarios?
JS Part 4