news 2026/4/17 15:46:48

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/4/18 11:20:13

【收藏必看】RAG不死!2025年五大发展趋势:从小白到大牛的进阶指南

RAG技术虽经历"已死"争议&#xff0c;但正从独立框架演变为智能体生态的关键子模块。2025年将迎来五大趋势&#xff1a;与Agent深度融合、多模态体系化建设、GraphRAG精细化动态化、轻量化低成本方案及行业定制化发展。文章详细分析了各趋势的技术细节、应用场景及实…

作者头像 李华
网站建设 2026/4/18 6:23:35

[todo]llm开发调研

思考 现在的这些最佳实践到底是需要考虑开发者的体验&#xff0c;还是LLM的体验呢&#xff1f; 节省token就必然会牺牲可读性

作者头像 李华
网站建设 2026/4/18 8:09:49

iperf 网络性能测试完整指南(含多服务端测试)

iperf 网络性能测试完整指南&#xff08;含多服务端测试&#xff09; iperf 是一款常用的网络性能测试工具&#xff0c;用于测量 TCP 和 UDP 网络带宽、延迟、抖动等核心指标&#xff0c;适配单服务端、多服务端等多种测试场景。本文整合基础用法与多服务端测试技巧&#xff0…

作者头像 李华
网站建设 2026/4/18 6:25:01

基于 PLC 的农村户用光沼联合发电控制系统的研究(设计源文件+万字报告+讲解)(支持资料、图片参考_相关定制)_文章底部可以扫码

基于 PLC 的农村户用光沼联合发电控制系统的研究(设计源文件万字报告讲解)&#xff08;支持资料、图片参考_相关定制&#xff09;_文章底部可以扫码目 录 摘 要 I Abstract II 第一章 绪论 1 1.1选题的背景及其意义 1 1.2国内外发展现状及研究现状 2 1.2.1太阳光热国外发展现状…

作者头像 李华
网站建设 2026/4/18 3:24:42

基于 PLC 的矿井提升机智能型电控系统的设计与研究(设计源文件+万字报告+讲解)(支持资料、图片参考_相关定制)_文章底部可以扫码

基于 PLC 的矿井提升机智能型电控系统的设计与研究(设计源文件万字报告讲解)&#xff08;支持资料、图片参考_相关定制&#xff09;_文章底部可以扫码 摘 要 矿井提升机的任务是实现矿井地面与矿下的联系&#xff0c;其主要负责矿井工作人员、物料以及机械设备的运输。在矿井日…

作者头像 李华
网站建设 2026/4/18 8:52:03

用惯了QTimer定时器,如何快速在纯 C++ 项目中替换?

是否在使用 Qt 开发时&#xff0c;习惯了 Qt 提供的 QTimer 类&#xff1f;QTimer 简单易用&#xff0c;可以让你轻松地在定时任务中设置时间间隔并执行回调函数。可是&#xff0c;当你突然需要在没有 Qt 环境的纯 C 项目中进行开发时&#xff0c;你会发现没有了 QTimer&#x…

作者头像 李华