news 2026/9/12 12:27:46

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/9/8 10:14:38

Jmeter简单的压力测试

&#x1f345; 点击文末小卡片&#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快今天我们一起利用Apache Jmeter&#xff08;一种接口测试工具&#xff09;来进行压力测试学习。压力测试主要目的是测试负载均衡的实现效果。安装Jmeter这里就不做阐…

作者头像 李华
网站建设 2026/9/3 3:22:56

fio 硬盘性能测试完整指南

fio 硬盘性能测试完整指南 fio&#xff08;Flexible I/O Tester&#xff09;是一款开源、灵活的磁盘I/O性能测试工具&#xff0c;支持多种I/O引擎、测试场景和参数配置&#xff0c;可精准测量硬盘&#xff08;机械硬盘HDD、固态硬盘SSD&#xff09;、分区及文件系统的读写性能…

作者头像 李华
网站建设 2026/9/9 15:04:07

基于PLC的包裹仓库分拣系统设计 (设计源文件+万字报告+讲解)(支持资料、图片参考_相关定制)_文章底部可以扫码

、基于PLC的包裹仓库分拣系统设计 (设计源文件万字报告讲解)&#xff08;支持资料、图片参考_相关定制&#xff09;_文章底部可以扫码 摘 要 在工业不断发展的推动下&#xff0c;PLC技术在控制方面受到越来越多的关注&#xff0c;自动化、智能化的分拣装置在物流、制造等行业广…

作者头像 李华
网站建设 2026/9/2 17:23:22

基于单片机的家居环境监测系统的研究与设计

基于单片机的家居环境监测系统的研究与设计 第一章 绪论 传统家居环境监测多依赖单一功能的便携式检测仪&#xff0c;存在监测维度少、数据无法实时汇总、缺乏预警机制、需人工查看数据等问题&#xff0c;难以满足现代家庭对空气质量、温湿度、安全防护等全维度环境管控的需求。…

作者头像 李华
网站建设 2026/9/3 4:36:02

基于单片机的智能温控风扇设计

基于单片机的智能温控风扇设计 第一章 绪论 传统风扇多采用手动档位调节风速&#xff0c;存在温控精度低、无法根据环境温度自动适配风速、能耗高、缺乏人性化交互等问题&#xff0c;难以满足居家、办公、小型机房等场景下精细化控温需求。STM32单片机凭借高精度ADC采集能力、…

作者头像 李华
网站建设 2026/9/12 9:09:34

nodejs+vue的智慧博物馆文创产品商城及预约平台的设计与实现

文章目录智慧博物馆文创产品商城及预约平台的设计与实现摘要--nodejs技术栈--结论源码文档获取/同行可拿货,招校园代理 &#xff1a;文章底部获取博主联系方式&#xff01;智慧博物馆文创产品商城及预约平台的设计与实现摘要 背景与目标 随着数字化技术的普及&#xff0c;博物…

作者头像 李华