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

网站维护描述西安便民信息发布平台

网站维护描述,西安便民信息发布平台,给人做网站的,杭州建设网通知公告栏绘制加载动画#xff1a;由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类#xff1a;LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态#xff0c;而 Load… 绘制加载动画由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态而 LoadingPainter 则负责绘制动画。 效果展示视频地址https://live.csdn.net/v/417383 资源文件下载地址https://download.csdn.net/download/yang_6799/89639107 1. 定义 LoadingScreen 类 LoadingScreen 类是一个 StatefulWidget它管理 AnimationController 和 Animation 对象。AnimationController 用于控制动画的播放Animation 对象则表示动画的具体值。 import package:flutter/material.dart; import dart:math;void main() runApp(MyApp());class MyApp extends StatelessWidget {overrideWidget build(BuildContext context) {return MaterialApp(home: LoadingScreen(),);} }以上代码定义了 MyApp 和 LoadingScreen 两个类其中 MyApp 是应用的入口点而 LoadingScreen 则是主要的动画屏幕。 2. 实现 _LoadingScreenState 类 在 LoadingScreen 类中我们要实现 _LoadingScreenState它是实际负责动画逻辑的地方。 class LoadingScreen extends StatefulWidget {override_LoadingScreenState createState() _LoadingScreenState(); }class _LoadingScreenState extends StateLoadingScreenwith SingleTickerProviderStateMixin {AnimationController? _controller;Animationdouble? _animation;overridevoid initState() {super.initState();_controller AnimationController(vsync: this,duration: Duration(seconds: 3),)..repeat();_animation Tweendouble(begin: 0, end: 1).animate(_controller!);}overridevoid dispose() {_controller?.dispose();super.dispose();}overrideWidget build(BuildContext context) {return Scaffold(backgroundColor: Colors.white,body: Center(child: CustomPaint(painter: LoadingPainter(animation: _animation!),child: SizedBox(width: 200.0,height: 200.0,),),),);} }详解 initState 方法 初始化时创建 AnimationController 并设置动画持续时间为 3 秒。调用 …repeat() 方法让动画重复播放。使用 Tween 创建一个从 0 到 1 的动画并与控制器关联。 dispose 方法 销毁控制器以释放资源。 build 方法 使用 CustomPaint 来绘制自定义内容这里我们指定了 LoadingPainter 作为画笔然后设置了一个 200x200 的 SizedBox 来容纳绘制内容。 3. 定义 LoadingPainter 类 LoadingPainter 类继承自 CustomPainter负责实际绘制每个小圆。我们需要计算每个小圆的位置、大小和透明度以便实现顺时针方向依次从小到大的动画效果。 class LoadingPainter extends CustomPainter {final Animationdouble animation;LoadingPainter({required this.animation}) : super(repaint: animation);overridevoid paint(Canvas canvas, Size size) {double radius size.width / 2;int circleCount 12;double baseCircleRadius 5.0;double maxCircleRadius 15.0;Paint paint Paint()..style PaintingStyle.fill;for (int i 0; i circleCount; i) {double angle (i / circleCount) * 2 * pi;double x radius radius * cos(angle);double y radius radius * sin(angle);// 计算每个小圆在动画中的进度并加入相位偏移double progress (animation.value - i / circleCount) % 1;double scaleFactor (sin(progress * 2 * pi) 1) / 2;double currentRadius baseCircleRadius scaleFactor * (maxCircleRadius - baseCircleRadius);// 确保透明度不低于 0.3double opacity 0.3 0.7 * scaleFactor;paint.color Colors.blue.withOpacity(opacity);canvas.drawCircle(Offset(x, y), currentRadius, paint);}}overridebool shouldRepaint(covariant CustomPainter oldDelegate) {return true;} }详解 构造函数 接受一个 Animation 类型参数并调用 super(repaint: animation) 以便在动画值改变时触发重绘。 paint 方法 初始化一些常量包括大圆的半径、小圆的数量以及小圆的最小和最大半径。使用 Paint 进行绘制配置。遍历每个小圆并根据其序号和当前动画进度计算位置和大小。通过 sin 函数计算缩放因子 scaleFactor并使用该因子调整小圆的半径和透明度。最后通过 canvas.drawCircle 在计算出的坐标处绘制每个小圆。 4. 总结 在这篇文章中我们学习了如何使用 Flutter 创建一个加载动画。通过 AnimationController 和 CustomPainter我们可以轻松地实现各种复杂的动画效果。这种加载动画不仅可以提升用户体验还可以让您的应用看起来更加专业。
http://www.hkea.cn/news/14465498/

相关文章:

  • 淄博哪有培训做网站的网站建设满意度调查问卷
  • 网站建设安全性指标蓝色企业网站配色
  • 建设网站制作哪家好网站架构设计英文翻译
  • 万网云虚拟主机上传网站吗中国住房和城乡建设部网站安全
  • 高端网站建设哪家便宜灯具设计网站推荐
  • 网站更换服务器 seo点广告挣钱网站有哪些
  • wordpress站点打不开建站网站教程视频
  • 推广自己的网站需要怎么做小学六年级做的网站
  • 二级学院网站建设整改方案西安市做网站的
  • 网站系统建设开票要开什么磁力猫torrentkitty官网
  • 多语言网站建设应注意哪些事项wordpress企业官网主题下载地址
  • 图文网站模版金蝶erp
  • 网站被入侵郑州企业自助建站
  • 做视频直播的网站有哪些如何修改wordpress关键词
  • 自己建个电影网站可以吗公司注册网站的费用多少
  • 口碑好的广州做网站微信公众平台注册官网
  • 东城专业网站建设公司seo推广哪家公司好
  • 镜像网站是怎么做的网站建设与管理教学视频
  • 网站建设需要备案吗杭州网站制作哪家好
  • 如何用二级域名做网站布奏重庆建网站 私单
  • 鄂州门户网站上海网站建设优化seo
  • 超级简历模板官网百度百科优化排名
  • 地方门户网站的出路3天引流800个人技巧
  • 桂林北站到两江机场大巴时刻表53货源网下载app
  • 网站建设需求分析要做的事做网站的开发语言
  • 聊城建设路小学网站wordpress 自动登录
  • 网站开发vscwordpress文章标题总有网站名
  • 汕头网站搜索优化seo 优化一般包括哪些内容
  • 数据库作业代做网站网站实名认证功能怎么做
  • 福田搭建网站费用源码下载网