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

Flutter 自定义view

带进度动画的圆环。没gif,效果大家自行脑补。

继承CustomPainterpaint()方法中拿到canvas,绘制API和android差不多。

import 'package:flutter/material.dart';class ProgressRingPainter extends CustomPainter {double strokeWidth = 20;Color _colorBg = Colors.white10;final double progress;ProgressRingPainter({this.progress});@overridevoid paint(Canvas canvas, Size size) {var xCenter = size.width / 2;var yCenter = size.height / 2;Rect rect = Rect.fromCenter(center: Offset(xCenter, yCenter),width: size.width,height: size.height);var paintBg = Paint()..style = PaintingStyle.stroke..isAntiAlias = true..strokeWidth = strokeWidth..color = _colorBg;List<Color> colors = List();colors.add(Colors.white70);colors.add(Colors.white);colors.add(Colors.white70);var paint = Paint()..style = PaintingStyle.stroke..isAntiAlias = true..strokeWidth = strokeWidth..shader = LinearGradient(colors: colors).createShader(rect);canvas.drawArc(rect, 0, 36, false, paintBg);canvas.drawArc(rect, 4.5, -progress, false, paint);}@overridebool shouldRepaint(CustomPainter oldDelegate) {return true;}
}
import 'package:flutter/material.dart';
import 'package:flutter_app_demo/widget/progress_ring_paint.dart';AnimationController animationController;class ProgressRing extends StatefulWidget {@overrideState<StatefulWidget> createState() {return ProgressRingState();}static void startAnimation() {animationController.forward(from: 0);}
}class ProgressRingState extends State<ProgressRing>with SingleTickerProviderStateMixin {Animation<double> animation;AnimationController controller;@overridevoid initState() {super.initState();controller = new AnimationController(duration: const Duration(seconds: 5), vsync: this);animation = CurvedAnimation(parent: controller, curve: Curves.linear);animation = new Tween(begin: 0.0, end: 36.0).animate(animation);controller.forward(from: 0);animationController = controller;}@overridevoid dispose() {controller.dispose();super.dispose();}@overrideWidget build(BuildContext context) {return AnimatedProgressRing(animation: animation);}
}class AnimatedProgressRing extends AnimatedWidget {AnimatedProgressRing({Key key, Animation<double> animation}): super(key: key, listenable: animation);Widget build(BuildContext context) {final Animation<double> animation = listenable;return CustomPaint(size: Size(200, 200),painter: ProgressRingPainter(progress: animation.value),);}
}
http://www.lryc.cn/news/114605.html

相关文章:

  • Ubuntu新装系统报错:sudo: vim:找不到命令
  • Vue3自定义简单的Swiper滑动组件-触控板滑动鼠标滑动左右箭头滑动-demo
  • 三个主流数据库(Oracle、MySQL和SQL Server)的“单表造数
  • TypeScript 中【class类】与 【 接口 Interfaces】的联合搭配使用解读
  • JavaWeb 手写Tomcat底层机制
  • Gof23设计模式之组合模式
  • 龙芯积极研发二进制翻译,提升软硬件兼容性,提高LoongArch架构
  • 3天爆肝整理,自动化测试-YAML文件读写实战(超细总结)
  • 算法通关村——透彻理解二分查找
  • PAT(Advanced Level)刷题指南 —— 第六弹(⭐有点难度⭐)
  • 个人对智能家居平台选择的思考
  • 无涯教程-Lua - while语句函数
  • MySql学习3:常用函数
  • 24届近5年江南大学自动化考研院校分析
  • C++ 数组
  • Android LinearLayout dynamic add child ImageView,Glide load,kotlin
  • HTML 是什么?它的全称是什么?
  • ATF(TF-A)安全通告
  • LVS—DR集群的搭建
  • 如何理解容量测试?如何做容量测试?
  • 文件上传漏洞(webshell)
  • .net几行代码音乐API各排行榜 热搜 入库
  • 使用gpt对对话数据进行扩增,对话数据扩增,数据增强
  • 算法练习工程1.2
  • 数字IC流片经历有多重要?怎样才能有流片机会?
  • fontfaceobserver 第三方字体加载优化方案
  • laravel安装composer依赖
  • 问题聚集度Hive SQL
  • Windows11右键菜单
  • 篇十四:观察者模式:对象间的通知与更新