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

Flutter + OpenHarmony 进度环组件开发实战

Flutter OpenHarmony 进度环组件开发实战欢迎加入开源鸿蒙跨平台社区→ https://openharmonycrosplatform.csdn.net一、效果展示 运行效果预览在鸿蒙虚拟机上运行后的实际效果如下基础样式 实线进度环 - 圆滑的实线进度条渐变进度环 - 蓝紫渐变效果虚线进度环 - 20段虚线组成分段进度环 - 8段分段显示不同尺寸 60px - 小型进度环4px粗细100px - 标准进度环8px粗细140px - 大型进度环12px粗细自定义颜色 红色进度环绿色进度环蓝色进度环橙色进度环渐变效果 红橙渐变 - 暖色调蓝青渐变 - 冷色调紫粉渐变 - 梦幻色调多环进度 三层嵌套进度环蓝、绿、橙三色中心显示完成率自定义中心 爱心图标对勾图标沙漏图标交互式调节 滑块控制进度实时更新显示平滑动画过渡 四种样式对比图示实线样式 渐变样式 虚线样 式 分段样式 ╭───╮ ╭───╮ ╭─┬─╮ ╭─┬─╮ │ 75%│ │░65%│ │ │ │ │ │ │ ╰───╯ ╰───╯ ╰─┴─╯ ╰─┴─╯ 连续实线 渐变色彩 20段虚 线 8段分段 多环进度效果多环嵌套 ╭─────────╮ ╭┤ 85% ├╮ ╭││ 完成率 ││╮ │╰┤ ├╯│ │ ╰─────────╯ │ ╰─────────────╯ 蓝 绿 橙 三环二、组件概述进度环是展示任务完成度、数据加载进度、目标达成率等信息的重要组件。相比线性进度条圆形进度环更加美观、节省空间。在 OpenHarmony 环境下开发 Flutter 应用时进度环组件需要支持多种视觉样式、渐变效果、多环嵌套等功能。三、核心功能特性✅ 四种视觉样式 - 实线、渐变、虚线、分段✅ 渐变色彩支持 - SweepGradient实现渐变✅ 多环进度显示 - 嵌套多层进度环✅ 自定义中心内容 - 图标、文本可配置✅ 平滑动画过渡 - 进度变化时动画效果✅ 灵活尺寸配置 - 大小、粗细可调节四、技术实现架构4.1 进度环样式枚举enum ProgressRingStyle { solid, // 实线样式 gradient, // 渐变样式 dashed, // 虚线样式 segmented // 分段样式 }4.2 进度环动画枚举enum ProgressRingAnimation { smooth, // 平滑动画 bounce, // 弹跳动画 pulse, // 脉冲动画 rotate // 旋转动画 }4.3 组件属性定义class CustomProgressRing extends StatefulWidget { final double progress; // 进度值 0-1 final double size; // 尺寸 final double strokeWidth; // 线条粗细 final Color? backgroundColor; // 背景色 final Color? progressColor; // 进度色 final ListColor? gradientColors; // 渐变色 final ProgressRingStyle style; // 样式 final ProgressRingAnimation animation; // 动画 final bool showPercentage; // 显示百 分比 final TextStyle? percentageStyle; // 百分比样式 final Widget? centerWidget; // 中心组件 final Duration animationDuration; // 动画时长 final double startAngle; // 起始角度 }五、CustomProgressRing 核心实现5.1 动画控制器class _CustomProgressRingState extends StateCustomProgressRing with SingleTickerProviderStateMixin { late AnimationController _controller; late Animationdouble _animation; override void initState() { super.initState(); _controller AnimationController( vsync: this, duration: widget. animationDuration, ); _animation Tweendouble (begin: 0, end: widget.progress. clamp(0.0, 1.0)).animate( CurvedAnimation(parent: _controller, curve: Curves. easeInOutCubic), ); _controller.forward(); } override void didUpdateWidget (CustomProgressRing oldWidget) { super.didUpdateWidget (oldWidget); if (oldWidget.progress ! widget.progress) { _animation Tweendouble( begin: _animation.value, end: widget.progress.clamp (0.0, 1.0), ).animate( CurvedAnimation(parent: _controller, curve: Curves. easeInOutCubic), ); _controller.reset(); _controller.forward(); } } override void dispose() { _controller.dispose(); super.dispose(); } }动画原理 使用 AnimationController 控制动画Curves.easeInOutCubic 实现平滑过渡didUpdateWidget 监听进度变化进度变化时从当前值动画到新值5.2 布局构建override Widget build(BuildContext context) { final isDark Theme.of(context). brightness Brightness.dark; final bgColor widget. backgroundColor ?? (isDark ? Colors.grey[800]! : Colors.grey [200]!); final pColor widget. progressColor ?? Theme.of (context).colorScheme.primary; return AnimatedBuilder( animation: _animation, builder: (context, child) { return SizedBox( width: widget.size, height: widget.size, child: Stack( alignment: Alignment. center, children: [ CustomPaint( size: Size(widget. size, widget.size), painter: _ProgressRingPainter( progress: _animation.value, backgroundColor: bgColor, progressColor: pColor, gradientColors: widget. gradientColors, strokeWidth: widget. strokeWidth, style: widget.style, startAngle: widget. startAngle, ), ), if (widget. showPercentage || widget.centerWidget ! null) widget. centerWidget ?? _buildPercentageText (isDark), ], ), ); }, ); }布局原理 使用 Stack 叠加布局CustomPaint 绘制进度环中心显示百分比或自定义组件5.3 CustomPainter 绘制器class _ProgressRingPainter extends CustomPainter { final double progress; final Color backgroundColor; final Color progressColor; final ListColor? gradientColors; final double strokeWidth; final ProgressRingStyle style; final double startAngle; override void paint(Canvas canvas, Size size) { final center Offset(size. width / 2, size.height / 2); final radius (size.width - strokeWidth) / 2; _drawBackgroundRing(canvas, center, radius); _drawProgressRing(canvas, center, radius, size); } void _drawBackgroundRing(Canvas canvas, Offset center, double radius) { final paint Paint() ..color backgroundColor ..style PaintingStyle.stroke ..strokeWidth strokeWidth ..strokeCap StrokeCap.round; canvas.drawCircle(center, radius, paint); } }5.4 实线样式绘制void _drawSolidRing(Canvas canvas, Offset center, double radius, double startAngle, double sweepAngle) { final paint Paint() ..color progressColor ..style PaintingStyle.stroke ..strokeWidth strokeWidth ..strokeCap StrokeCap.round; canvas.drawArc( Rect.fromCircle(center: center, radius: radius), startAngle, sweepAngle, false, paint, ); }5.5 渐变样式绘制void _drawGradientRing(Canvas canvas, Offset center, double radius, double startAngle, double sweepAngle, Size size) { final colors gradientColors ?? [progressColor, progressColor. withOpacity(0.5)]; final rect Rect.fromCircle (center: center, radius: radius); final paint Paint() ..shader SweepGradient( startAngle: startAngle, endAngle: startAngle sweepAngle, colors: colors, tileMode: TileMode.clamp, ).createShader(rect) ..style PaintingStyle.stroke ..strokeWidth strokeWidth ..strokeCap StrokeCap.round; canvas.drawArc(rect, startAngle, sweepAngle, false, paint); }渐变原理 使用 SweepGradient 创建扫描渐变渐变角度跟随进度角度TileMode.clamp 防止溢出5.6 虚线样式绘制void _drawDashedRing(Canvas canvas, Offset center, double radius, double startAngle, double sweepAngle) { final paint Paint() ..color progressColor ..style PaintingStyle.stroke ..strokeWidth strokeWidth ..strokeCap StrokeCap.round; const dashCount 20; const dashSpace 3. 141592653589793 / 180 * 8; final dashAngle (sweepAngle - dashSpace * (dashCount - 1)) / dashCount; for (int i 0; i dashCount; i ) { final currentStartAngle startAngle i * (dashAngle dashSpace); canvas.drawArc( Rect.fromCircle(center: center, radius: radius), currentStartAngle, dashAngle, false, paint, ); } }虚线原理 固定20段虚线计算每段角度和间隔循环绘制每段弧线5.7 分段样式绘制void _drawSegmentedRing(Canvas canvas, Offset center, double radius, double startAngle, double sweepAngle) { final paint Paint() ..color progressColor ..style PaintingStyle.stroke ..strokeWidth strokeWidth ..strokeCap StrokeCap.round; const segmentCount 8; const segmentSpace 3. 141592653589793 / 180 * 6; final segmentAngle (sweepAngle - segmentSpace * (segmentCount - 1)) / segmentCount; for (int i 0; i segmentCount; i) { final currentStartAngle startAngle i * (segmentAngle segmentSpace); canvas.drawArc( Rect.fromCircle(center: center, radius: radius), currentStartAngle, segmentAngle, false, paint, ); } }六、MultiProgressRing 多环进度实现6.1 多环数据结构class RingData { final double progress; // 进 度值 final Color color; // 颜 色 final Color? backgroundColor; // 背景色 final double strokeWidth; // 线 条粗细 const RingData({ required this.progress, required this.color, this.backgroundColor, this.strokeWidth 8, }); }6.2 多环布局class MultiProgressRing extends StatelessWidget { final ListRingData rings; final double size; final Widget? centerWidget; override Widget build(BuildContext context) { return SizedBox( width: size, height: size, child: Stack( alignment: Alignment.center, children: [ ...rings.asMap().entries. map((entry) { final index entry.key; final ring entry. value; final ringSize size - (index * ring. strokeWidth * 2.5); return Positioned( child: CustomProgressRing( progress: ring. progress, size: ringSize, strokeWidth: ring. strokeWidth, progressColor: ring. color, backgroundColor: ring. backgroundColor, showPercentage: false, ), ); }), if (centerWidget ! null) centerWidget!, ], ), ); } }多环原理 使用 Stack 叠加多个进度环每个环的尺寸递减中心显示自定义组件七、使用示例集锦示例1基础进度环CustomProgressRing( progress: 0.75, )示例2渐变进度环CustomProgressRing( progress: 0.65, style: ProgressRingStyle.gradient, gradientColors: [Colors.blue, Colors.purple], )示例3虚线进度环CustomProgressRing( progress: 0.55, style: ProgressRingStyle.dashed, )示例4分段进度环CustomProgressRing( progress: 0.85, style: ProgressRingStyle. segmented, )示例5自定义尺寸CustomProgressRing( progress: 0.7, size: 140, strokeWidth: 12, )示例6自定义颜色CustomProgressRing( progress: 0.8, progressColor: Colors.red, backgroundColor: Colors.red. withOpacity(0.2), )示例7自定义中心CustomProgressRing( progress: 0.72, centerWidget: Icon(Icons. favorite, color: Colors.red, size: 32), )示例8多环进度MultiProgressRing( size: 160, rings: [ RingData(progress: 0.85, color: Colors.blue, strokeWidth: 10), RingData(progress: 0.65, color: Colors.green, strokeWidth: 10), RingData(progress: 0.45, color: Colors.orange, strokeWidth: 10), ], centerWidget: Text(85%), )八、性能优化策略8.1 绘制优化CustomPainter 高效的自定义绘制shouldRepaint 仅在必要时重绘局部刷新 避免全局重建8.2 动画优化AnimatedBuilder 局部重建Curves.easeInOutCubic 流畅的动画曲线单次动画 避免重复播放8.3 内存优化及时dispose 释放动画控制器轻量绘制 仅绘制必要元素九、常见问题解答Q1: 如何修改进度环大小设置 size 和 strokeWidth 参数CustomProgressRing( progress: 0.7, size: 140, strokeWidth: 12, )Q2: 如何隐藏百分比显示设置 showPercentage: false CustomProgressRing( progress: 0.7, showPercentage: false, )Q3: 如何自定义起始角度设置 startAngle 参数角度制CustomProgressRing( progress: 0.7, startAngle: 0, // 从右侧开始 )Q4: 如何修改动画时长设置 animationDuration 参数CustomProgressRing( progress: 0.7, animationDuration: const Duration (milliseconds: 2000), )Q5: 如何创建多环进度使用 MultiProgressRing 组件MultiProgressRing( rings: [ RingData(progress: 0.8, color: Colors.blue), RingData(progress: 0.6, color: Colors.green), ], )Q6: 如何使用渐变色设置 style: ProgressRingStyle.gradient 和 gradientColors CustomProgressRing( progress: 0.7, style: ProgressRingStyle.gradient, gradientColors: [Colors.red, Colors.orange], )运行效果截图十、总结本文详细介绍了如何在 Flutter OpenHarmony 环境中开发一个功能完善的进度环组件。该组件具备以下技术亮点 丰富的样式选择 - 四种风格适配不同设计 渐变色彩支持 - SweepGradient实现流畅渐变⚡ 多环嵌套显示 - 支持多层进度环叠加 高度可定制 - 尺寸、颜色、动画全面可控实际应用场景 任务完成度数据加载进度目标达成率技能熟练度健康数据展示

相关文章:

Flutter + OpenHarmony 进度环组件开发实战

Flutter OpenHarmony 进度环组件开发实战 欢迎加入开源鸿蒙跨平台社区→ https://openharmonycrosplatform.csdn.net 一、效果展示 📱 运行效果预览 在鸿蒙虚拟机上运行后的实际效果如下: 基础样式 :实线进度环 - 圆滑的实线进度条渐变进度环…...

Dragonfly2性能优化技巧:5个关键配置让你的网络传输速度提升300%

Dragonfly2性能优化技巧:5个关键配置让你的网络传输速度提升300% 【免费下载链接】Dragonfly2 Delivers efficient, stable, and secure data distribution and acceleration powered by P2P technology, with an optional content‑addressable filesystem that ac…...

wvp-GB28181-pro容器化部署:5分钟构建专业视频监控平台

wvp-GB28181-pro容器化部署:5分钟构建专业视频监控平台 【免费下载链接】wvp-GB28181-pro 基于GB28181-2016、部标808、部标1078标准实现的开箱即用的网络视频平台。自带管理页面,支持NAT穿透,支持海康、大华、宇视等品牌的IPC、NVR接入。支持…...

如何高效使用Dragonfly2 API:RESTful接口和gRPC服务的完整指南

如何高效使用Dragonfly2 API:RESTful接口和gRPC服务的完整指南 【免费下载链接】Dragonfly2 Delivers efficient, stable, and secure data distribution and acceleration powered by P2P technology, with an optional content‑addressable filesystem that acce…...

基于MCP协议构建Notion与AI助手无缝集成的实践指南

1. 项目概述:一个让Notion与AI无缝对话的桥梁 如果你和我一样,日常重度依赖Notion来管理项目、记录灵感和整理知识库,同时又频繁使用各类AI助手(比如ChatGPT、Claude)来辅助思考和创作,那么你肯定遇到过这样…...

Tomato-Novel-Downloader:一站式番茄小说下载与格式转换终极指南

Tomato-Novel-Downloader:一站式番茄小说下载与格式转换终极指南 【免费下载链接】Tomato-Novel-Downloader 番茄小说下载器不精简版 项目地址: https://gitcode.com/gh_mirrors/to/Tomato-Novel-Downloader 你是否曾经在番茄小说上遇到心仪的作品&#xff0…...

应变片称重技术原理与惠斯通电桥应用详解

1. 应变片称重技术的前世今生第一次接触应变片是在大学实验室里,当时教授让我们用指甲轻轻按压那片薄如蝉翼的金属箔,万用表上的数字立刻跳了起来。这种将机械力转化为电信号的神奇元件,如今已成为现代称重技术的核心部件。从超市收银台的电子…...

核心组件大换血:Backbone与Neck魔改篇:YOLO26魔改Backbone:缝合GhostNetV2,参数量锐减与特征重用双管齐下

开篇:当YOLO遇上边缘部署的现实之痛 2026年初,Ultralytics正式发布了YOLO26,一个专为边缘和低功耗环境从零重新设计的统一检测架构。根据官方介绍,YOLO26摒弃了过度复杂的图结构和DFL等计算密集型模块,回归简洁架构,其nano版本在标准CPU上运行速度相比前代提升了高达43%…...

告别TP2912依赖?国产芯XS5013实战评测:安防摄像头ISP芯片选型避坑指南

XS5013实战评测:国产ISP芯片如何破解安防摄像头选型困局 当某国际大厂突然通知交期延长至52周时,我们研发部的会议室空气瞬间凝固。作为一家专注智能安防的中型方案商,仓库里TP2912的库存只够支撑三个月量产——这个真实发生在2022年Q4的供应…...

终极DVWA靶场定制指南:5步快速开发自定义漏洞模块

终极DVWA靶场定制指南:5步快速开发自定义漏洞模块 【免费下载链接】DVWA Damn Vulnerable Web Application (DVWA) 项目地址: https://gitcode.com/gh_mirrors/dv/DVWA Damn Vulnerable Web Application (DVWA) 是一款广泛使用的Web安全学习平台,…...

Manus被叫停:中国AI出海,「境外换壳再被收购」这条路死了

前言 2026年4月27日,国家发改委发布公告:依法对Meta收购Manus项目作出禁止投资决定,要求双方撤销交易。 这是《外商投资安全审查办法》2021年实施以来,首个被公开叫停的AI领域外资收购案。20亿美元,谈判十余天&#…...

逆向工程与破解技术:Hacking项目实战教程

逆向工程与破解技术:Hacking项目实战教程 【免费下载链接】Hacking 🌐Collate and develop network security, Hackers technical documentation and tools, code. 项目地址: https://gitcode.com/gh_mirrors/ha/Hacking Hacking项目是一个专注于…...

如何用Color Thief快速捕捉季节性色彩:打造完美视觉体验的完整指南

如何用Color Thief快速捕捉季节性色彩:打造完美视觉体验的完整指南 【免费下载链接】color-thief Grab the color palette from an image using just Javascript. Works in the browser and in Node. 项目地址: https://gitcode.com/gh_mirrors/co/color-thief …...

gpiozero远程GPIO控制:突破物理限制的物联网开发

gpiozero远程GPIO控制:突破物理限制的物联网开发 【免费下载链接】gpiozero A simple interface to GPIO devices with Raspberry Pi 项目地址: https://gitcode.com/gh_mirrors/gp/gpiozero gpiozero是一款专为树莓派设计的GPIO设备控制库,通过其…...

ComfyUI-AnimateDiff-Evolved终极指南:无限动画生成与高级采样技术

ComfyUI-AnimateDiff-Evolved终极指南:无限动画生成与高级采样技术 【免费下载链接】ComfyUI-AnimateDiff-Evolved Improved AnimateDiff for ComfyUI and Advanced Sampling Support 项目地址: https://gitcode.com/gh_mirrors/co/ComfyUI-AnimateDiff-Evolved …...

FLAC完全指南:无损音频压缩的终极解决方案

FLAC完全指南:无损音频压缩的终极解决方案 【免费下载链接】flac Free Lossless Audio Codec 项目地址: https://gitcode.com/gh_mirrors/fl/flac FLAC(Free Lossless Audio Codec)是一款开源的无损音频压缩软件,它能在不丢…...

P-tuning v2在序列标注任务中的惊人表现:NER、SRL任务深度分析

P-tuning v2在序列标注任务中的惊人表现:NER、SRL任务深度分析 【免费下载链接】P-tuning-v2 An optimized deep prompt tuning strategy comparable to fine-tuning across scales and tasks 项目地址: https://gitcode.com/gh_mirrors/pt/P-tuning-v2 P-tu…...

Apache Arrow C内存安全终极指南:托管代码中的零拷贝数据交换

Apache Arrow C内存安全终极指南:托管代码中的零拷贝数据交换 【免费下载链接】arrow Apache Arrow is a multi-language toolbox for accelerated data interchange and in-memory processing 项目地址: https://gitcode.com/gh_mirrors/arrow13/arrow Apac…...

让老电脑重获新生:MediaCreationTool.bat轻松安装Windows 11的完整方案

让老电脑重获新生:MediaCreationTool.bat轻松安装Windows 11的完整方案 【免费下载链接】MediaCreationTool.bat Universal MCT wrapper script for all Windows 10/11 versions from 1507 to 21H2! 项目地址: https://gitcode.com/gh_mirrors/me/MediaCreationTo…...

别再用笨重NAS了!手把手教你用闲置路由器刷OpenWrt跑Docker,挂青龙面板薅羊毛

闲置路由器变身全能服务器:OpenWrtDocker实战指南 家里那台落灰的旧路由器,其实藏着惊人的潜力。当大多数人还在纠结是否要花大价钱购置NAS时,极客们早已发现——一台刷了OpenWrt的路由器配合Docker容器,完全能实现轻量级家庭服务…...

DataRoom大屏设计器:企业级数据可视化架构深度解析

DataRoom大屏设计器:企业级数据可视化架构深度解析 【免费下载链接】DataRoom 🔥基于SpringBoot、MyBatisPlus、ElementUI、G2Plot、Echarts等技术栈的大屏设计器,具备目录管理、DashBoard设计、预览能力,支持MySQL、Oracle、Post…...

百度首页网页图片更多登录领域驱动设计(DDD)落地的最大障碍不是技术,而是…

一、DDD:软件测试从业者的新挑战在软件行业快速迭代的今天,领域驱动设计(DDD)凭借其对复杂业务场景的强大适配能力,逐渐成为架构设计的热门理念。对于软件测试从业者而言,DDD不仅是开发端的技术变革&#x…...

智能代码助手架构设计:从LLM集成到本地部署的完整实践

1. 项目概述:一个面向开发者的智能代码助手 最近在GitHub上看到一个挺有意思的项目,叫 haojichong/coding-codex 。乍一看这个名字,可能有点摸不着头脑,但如果你是一个经常和代码打交道的开发者,尤其是对提升编码效率…...

AI智能体操作系统:构建大规模智能体应用的基础设施

1. 项目概述:一个面向智能体的操作系统雏形 最近在开源社区里,一个名为 saadnvd1/agent-os 的项目引起了我的注意。乍一看这个标题,你可能会觉得它有些宏大甚至抽象——“智能体操作系统”?这听起来像是科幻电影里的概念。但当我…...

基于NLP与ASR的智能面试分析系统:架构设计与工程实践

1. 项目概述与核心价值面试,对于每一位求职者而言,都是一场信息密度极高的双向博弈。你需要在有限的时间内,尽可能精准地展示自己的技术栈、项目经验和解决问题的能力,同时还要快速解读面试官的提问意图,评估岗位匹配度…...

为什么92%的医疗AI项目卡在合规验收?Dify医疗问答模块的6类高危数据泄露场景及对应21项配置加固项(含真实渗透测试报告节选)

更多请点击: https://intelliparadigm.com 第一章:Dify医疗数据问答合规处理的行业困局与破局逻辑 在医疗AI应用落地过程中,基于Dify构建的问答系统常面临数据隐私、监管合规与临床可用性三重张力。患者病历、检验报告等敏感信息一旦未经脱敏…...

Nginx Proxy Manager自动化测试终极指南:如何确保配置变更零风险

Nginx Proxy Manager自动化测试终极指南:如何确保配置变更零风险 【免费下载链接】nginx-proxy-manager Docker container for managing Nginx proxy hosts with a simple, powerful interface 项目地址: https://gitcode.com/GitHub_Trending/ng/nginx-proxy-man…...

基于Claude API的智能代理框架:从对话到执行的AI应用开发实践

1. 项目概述:一个为Claude API设计的智能代理框架最近在折腾AI应用开发,特别是围绕Anthropic的Claude API构建一些自动化工作流时,发现了一个挺有意思的开源项目——openclaw-claude-delegate。这个项目本质上是一个为Claude设计的“智能代理…...

LFPO:无似然策略优化与掩码扩散模型结合实践

1. 项目概述LFPO(Likelihood-Free Policy Optimization)是一种创新的强化学习算法框架,它巧妙地将无似然优化方法与扩散模型相结合,通过策略梯度优化实现高效学习。这个项目的核心创新点在于引入了掩码扩散机制,使得模…...

React-Grid-Layout终极指南:深入解析网格项位置计算与坐标关系

React-Grid-Layout终极指南:深入解析网格项位置计算与坐标关系 【免费下载链接】react-grid-layout A draggable and resizable grid layout with responsive breakpoints, for React. 项目地址: https://gitcode.com/gh_mirrors/re/react-grid-layout React…...