app_progress.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:flutter/material.dart';
  2. import '../../theme/app_colors.dart';
  3. /// 进度状态
  4. enum ProgressStatus { active, success, error }
  5. /// 应用进度条组件
  6. class AppProgress extends StatelessWidget {
  7. final double value; // 0.0 - 1.0
  8. final ProgressStatus status;
  9. final bool showLabel;
  10. final String? label;
  11. final double? height;
  12. const AppProgress({
  13. Key? key,
  14. required this.value,
  15. this.status = ProgressStatus.active,
  16. this.showLabel = true,
  17. this.label,
  18. this.height,
  19. }) : super(key: key);
  20. @override
  21. Widget build(BuildContext context) {
  22. final progressValue = value.clamp(0.0, 1.0);
  23. final percent = (progressValue * 100).toInt();
  24. final displayLabel = label ?? '$percent%';
  25. Color getColor() {
  26. switch (status) {
  27. case ProgressStatus.active:
  28. return AppColors.primary;
  29. case ProgressStatus.success:
  30. return AppColors.success;
  31. case ProgressStatus.error:
  32. return AppColors.error;
  33. }
  34. }
  35. return Column(
  36. crossAxisAlignment: CrossAxisAlignment.start,
  37. mainAxisSize: MainAxisSize.min,
  38. children: [
  39. ClipRRect(
  40. borderRadius: BorderRadius.circular(4),
  41. child: LinearProgressIndicator(
  42. value: progressValue,
  43. backgroundColor: AppColors.borderLight,
  44. valueColor: AlwaysStoppedAnimation<Color>(getColor()),
  45. minHeight: height ?? 8,
  46. ),
  47. ),
  48. if (showLabel)
  49. Padding(
  50. padding: const EdgeInsets.only(top: 4),
  51. child: Text(
  52. displayLabel,
  53. style: TextStyle(fontSize: 12, color: AppColors.textSecondary),
  54. ),
  55. ),
  56. ],
  57. );
  58. }
  59. }