news 2026/10/28 20:53:29

Flutter---设备搜索动画效果(2)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Flutter---设备搜索动画效果(2)

详细介绍:优化成双色渐变版本

效果图:

关键点

把通用圆形设置为双色渐变,把动画值设置给透明度

代码实例

import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class DemoPage extends StatefulWidget{ const DemoPage({super.key}); @override State<StatefulWidget> createState() => _DemoPageState(); } class _DemoPageState extends State<DemoPage> with SingleTickerProviderStateMixin{ late AnimationController _controller; //动画控制器 late Animation<double> _sizeAnimation; late Animation<double> _colorAnimation; late Animation<double> _size1Animation; late Animation<double> _color1Animation; late Animation<double> _size2Animation; late Animation<double> _color2Animation; late Animation<double> _size3Animation; late Animation<double> _color3Animation; @override void initState(){ super.initState(); //初始化动画控制器 _controller = AnimationController( vsync: this, duration: Duration(seconds: 4) ); //TweenSequence - 动画序列 ;TweenSequenceItem - 序列项 _sizeAnimation = TweenSequence<double>([ TweenSequenceItem(tween:Tween<double>(begin: 50,end:130), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 130,end:210), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 210,end:290), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 290,end:50), weight: 1.0 ), ]).animate( CurvedAnimation(parent: _controller, curve: Curves.linear), ); _colorAnimation = TweenSequence<double>([ TweenSequenceItem( tween: Tween<double>(begin: 1.0,end: 0.7), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.7,end: 0.4), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.4,end: 0.1), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.0,end: 0.0), weight: 1.0, ), ]).animate(CurvedAnimation(parent: _controller, curve: Curves.linear)); _size1Animation = TweenSequence<double>([ TweenSequenceItem(tween:Tween<double>(begin: 130,end:210), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 210,end:290), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 290,end:50), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 50,end:130), weight: 1.0 ), ]).animate( CurvedAnimation(parent: _controller, curve: Curves.linear), ); _color1Animation = TweenSequence<double>([ TweenSequenceItem( tween: Tween<double>(begin: 0.7,end: 0.4), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.4,end: 0.1), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.0,end: 0.0), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 1.0,end: 0.7), weight: 1.0, ), ]).animate(CurvedAnimation(parent: _controller, curve: Curves.linear)); _size2Animation = TweenSequence<double>([ TweenSequenceItem(tween:Tween<double>(begin: 210,end:290), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 290,end:50), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 50,end:130), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 130,end:210), weight: 1.0 ), ]).animate( CurvedAnimation(parent: _controller, curve: Curves.linear), ); _color2Animation = TweenSequence<double>([ TweenSequenceItem( tween: Tween<double>(begin: 0.4,end: 0.1), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.0,end: 0.0), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 1.0,end: 0.7), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.7,end: 0.4), weight: 1.0, ), ]).animate(CurvedAnimation(parent: _controller, curve: Curves.linear)); _size3Animation = TweenSequence<double>([ TweenSequenceItem(tween:Tween<double>(begin: 290,end:50), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 50,end:130), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 130,end:210), weight: 1.0 ), TweenSequenceItem(tween:Tween<double>(begin: 210,end:290), weight: 1.0 ), ]).animate( CurvedAnimation(parent: _controller, curve: Curves.linear), ); _color3Animation = TweenSequence<double>([ TweenSequenceItem( tween: Tween<double>(begin: 0.0,end: 0.0), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 1.0,end: 0.7), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.7,end: 0.4), weight: 1.0, ), TweenSequenceItem( tween: Tween<double>(begin: 0.4,end: 0.1), weight: 1.0, ), ]).animate(CurvedAnimation(parent: _controller, curve: Curves.linear)); _controller.repeat(); //动画重复 } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: Center( child: Stack( children: [ // 动画部分 Center( child: AnimatedBuilder( animation: _controller, builder: (context, child) { return Stack( alignment: Alignment.center, children: [ _buildAnimatedCircle( size: _size3Animation.value, colorValue: _color3Animation.value, ), _buildAnimatedCircle( size: _size2Animation.value, colorValue: _color2Animation.value, ), _buildAnimatedCircle( size: _size1Animation.value, colorValue: _color1Animation.value, ), _buildAnimatedCircle( size: _sizeAnimation.value, colorValue: _colorAnimation.value, ), ], ); }, ), ), ], ), ), ); } // ============================构建动画圆形的通用方法========================== Widget _buildAnimatedCircle({ required double size, required double colorValue, Widget? child, }) { return Container( width: size, height: size, decoration: BoxDecoration( gradient: LinearGradient( begin: AlignmentGeometry.topCenter, end: AlignmentGeometry.bottomCenter, colors: [ Color(0xFF00E1FF).withOpacity(colorValue), Color(0xFF248EFF).withOpacity(colorValue), ] ), shape: BoxShape.circle, ), child: child != null ? Center(child: child) : null, ); } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/10/26 7:47:36

2026年九项AI变革技能

优秀的AI产品开发者能够平衡技术理想与用户需求&#xff0c;在保证质量的前提下快速验证想法。更重要的是具备数据驱动的优化意识&#xff0c;通过持续监控不断改进产品体验。在2026年&#xff0c;市场只会为真正解决实际问题的AI产品买单。随着AI技术从炫技阶段步入务实应用&a…

作者头像 李华
网站建设 2026/10/26 4:15:21

Agent Skills,让 AI 像老员工一样靠谱

让 AI 帮你处理公司特有的业务流程&#xff0c;它一脸懵&#xff1b;让它按照团队规范写代码&#xff0c;它自由发挥&#xff1b;让它用内部工具&#xff0c;它根本不知道那玩意儿存在。AI 很强&#xff0c;但它不懂你的「行话」。这就像招了一个名校毕业的实习生——聪明是聪明…

作者头像 李华
网站建设 2026/10/24 1:42:20

记忆的种子:构建有记忆力的AI

一旦记忆通过以加密的方式与来源及含义绑定&#xff0c;那么高质量的协作便成为了可能。各个智能体便可以在不泄露敏感数据的情况下&#xff0c;进行知识交换、引用或验证。 你也许注意到了&#xff0c;当我们每次打开ChatGPT、Claude或Gemini时&#xff0c;都需要从零开始。也…

作者头像 李华
网站建设 2026/10/23 17:02:26

混联磁路记忆电机的永磁特性参数设计

混联磁路记忆电机的永磁特性参数设计 第一章 绪论 记忆电机凭借其可在线调节气隙磁密、宽调速范围、高效率等优势&#xff0c;在电动汽车、航空航天、伺服驱动等领域展现出巨大应用潜力。混联磁路记忆电机结合了串联磁路与并联磁路的优点&#xff0c;通过合理配置永磁体与磁分路…

作者头像 李华
网站建设 2026/10/24 10:29:55

故障驱动器的数据恢复: 选择性镜像技术, 更快更安全地获取更多数据

传统镜像过程通常需要完整获取从零扇区到最大逻辑块寻址&#xff08;LBA&#xff09;的整个驱动器数据。然而&#xff0c;在许多数据恢复案例中&#xff0c;由于时间有限或硬盘严重老化&#xff0c;这种方法并不适用。本文将深入探讨各种选择性镜像技术&#xff0c;让镜像过程更…

作者头像 李华