当前位置: 首页 > news >正文

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, ); } }
http://www.jsqmd.com/news/341688/

相关文章:

  • 收藏备用|未来,AI究竟会替代多少程序员的工作?(附调研数据+学习指南)
  • 从工程视角看链路聚合:不只是带宽叠加那么简单
  • Spring Boot 4 新特性:模块化架构
  • AI辅助探索性测试:提升缺陷发现率的全面指南
  • 赋能北京商户!合肥三十六行北京分公司,多平台代运营实力派 - 野榜数据排行
  • 吐血推荐! AI论文网站 千笔 VS 灵感ai,专为本科生量身打造!
  • 大兴安岭英语雅思培训辅导机构推荐:2026权威出国雅思课程中心学校口碑排行榜 - 苏木2025
  • ‌模型漂移测试:确保AI系统长期稳定性的策略
  • 大兴安岭英语雅思培训辅导机构推荐-2026权威出国雅思课程中心学校口碑排行榜 - 苏木2025
  • 基于 RPA 模拟驱动的企业微信外部群自动化架构解析
  • 2026年陕西电线电缆回收厂家推荐:掘金“城市矿山”标杆企业解析 - 深度智识库
  • 试验品 #0
  • 企业微信 RPA 自动化避坑指南:外部群主动调用的安全边界在哪里?
  • 2026年陕西高温合金回收厂家TOP3推荐:三大标杆企业引领资源循环 - 深度智识库
  • 2026年高耐竹厂家Top5推荐:川企领衔,多元品质保障 - 深度智识库
  • 2026年陕西锆合金回收厂家权威推荐:专注资源再生的专业服务商 - 深度智识库
  • 230_尚硅谷_收支软件-明细和登记收入
  • PyTorch深度学习进阶(二)(批量归一化) - 教程
  • 全网最全8个降AI率平台 千笔帮你轻松降AIGC
  • 2026年 亚克力制品厂家推荐排行榜,亚克力板/厚板/泳池/鱼缸/水族箱/海洋馆,透明装饰/收纳盒/展示架/标牌/广告牌,匠心定制与创新应用深度解析 - 品牌企业推荐师(官方)
  • 2026年新西兰出国移民推荐:出国留学移民/出国移民条件/出国移民中介/出国移民政策精选 - 品牌推荐官
  • 2026年新疆驼奶粉品牌推荐:最好的驼奶粉/驼粉/驼奶粉精选 - 品牌推荐官
  • Shell Daily 2026-02-04: 身份查验 (Type vs Which)
  • Python 沙箱逃逸学习笔记
  • 沃尔玛购物卡变现的秘密:如何找到靠谱的回收平台? - 团团收购物卡回收
  • 基于 PLC 的矿井提升机智能型电控系统的设计与研究(设计源文件+万字报告+讲解)(支持资料、图片参考_相关定制)_文章底部可以扫码
  • 基于PLC称重混料小车运行控制系统(设计源文件+万字报告+讲解)(支持资料、图片参考_相关定制)_文章底部可以扫码
  • Active Exploration方向论文精读
  • 2026年户外建材(塑木/菠萝格/高耐竹等)优质厂家推荐 - 深度智识库
  • 瑞祥黑金卡回收选京回收还是猎卡?深度解析助抉择 - 京回收小程序