欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > Flutter:进度条封装

Flutter:进度条封装

2025/3/13 21:12:39 来源:https://blog.csdn.net/qq_40745143/article/details/146198859  浏览:    关键词:Flutter:进度条封装

在这里插入图片描述

封装一个自用的进度条:
属性包括:宽高,背景色,高亮色,圆角大小

组件

import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';class ProgressBar extends StatelessWidget {/// 进度值,范围0.0-1.0final double progress;/// 进度条宽度final double width;/// 进度条高度final double height;/// 背景颜色final Color backgroundColor;/// 高亮(进度)颜色final Color highlightColor;/// 圆角大小(背景和进度条使用相同的圆角)final double borderRadius;/// 动画持续时间final Duration animationDuration;/// 是否显示动画final bool animate;const ProgressBar({Key? key,required this.progress,required this.width,this.height = 40,this.backgroundColor = const Color(0xFF1D1D1D),this.highlightColor = Colors.blue,this.borderRadius = 20,this.animationDuration = const Duration(milliseconds: 300),this.animate = true,}) : assert(progress >= 0.0 && progress <= 1.0, "进度值必须在0.0到1.0之间"),super(key: key);@overrideWidget build(BuildContext context) {return Container(width: width.w,height: height.w,decoration: BoxDecoration(color: backgroundColor,borderRadius: BorderRadius.circular(borderRadius.w),),child: Stack(children: [// 进度条高亮部分animate ? AnimatedContainer(duration: animationDuration,width: width.w * progress,height: height.w,decoration: BoxDecoration(color: highlightColor,borderRadius: BorderRadius.circular(borderRadius.w),),): Container(width: width.w * progress,height: height.w,decoration: BoxDecoration(color: highlightColor,borderRadius: BorderRadius.circular(borderRadius.w),),),],),);}
}// 示例:如何使用
// ProgressBar(
//   progress: 0.7,
//   width: 300,
//   height: 24,
//   backgroundColor: Colors.grey[800]!,
//   highlightColor: Colors.blue,
//   borderRadius: 12,
// ) 

页面中使用

const ProgressBar(progress: 0.7,width: 160,height: 16,backgroundColor: AppTheme.color2223,highlightColor: AppTheme.primaryBlue,borderRadius: 8,animate: true,
)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词