import 'package:flutter/material.dart'; import '../../theme/app_colors.dart'; /// 进度状态 enum ProgressStatus { active, success, error } /// 应用进度条组件 class AppProgress extends StatelessWidget { final double value; // 0.0 - 1.0 final ProgressStatus status; final bool showLabel; final String? label; final double? height; const AppProgress({ Key? key, required this.value, this.status = ProgressStatus.active, this.showLabel = true, this.label, this.height, }) : super(key: key); @override Widget build(BuildContext context) { final progressValue = value.clamp(0.0, 1.0); final percent = (progressValue * 100).toInt(); final displayLabel = label ?? '$percent%'; Color getColor() { switch (status) { case ProgressStatus.active: return AppColors.primary; case ProgressStatus.success: return AppColors.success; case ProgressStatus.error: return AppColors.error; } } return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ ClipRRect( borderRadius: BorderRadius.circular(4), child: LinearProgressIndicator( value: progressValue, backgroundColor: AppColors.borderLight, valueColor: AlwaysStoppedAnimation(getColor()), minHeight: height ?? 8, ), ), if (showLabel) Padding( padding: const EdgeInsets.only(top: 4), child: Text( displayLabel, style: TextStyle(fontSize: 12, color: AppColors.textSecondary), ), ), ], ); } }