import 'package:flutter/material.dart';

class CustomProgressBar extends StatelessWidget {
  final double progress; // 进度值，范围 [0, 1]
  final Color color; // 进度条的颜色
  final double radius; // 进度条的圆角

  const CustomProgressBar({
    Key? key,
    required this.progress,
    required this.color,
    this.radius = 0,
  })  : assert(progress >= 0 && progress <= 1, '进度值必须在 0 到 1 之间'),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity, // 进度条宽度
      height: 16, // 进度条高度
      decoration: BoxDecoration(
        border: Border.all(color: color, width: 0.5), // 边框颜色和宽度
        borderRadius: BorderRadius.circular(radius), // 边框圆角
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(radius), // 内部进度条也有相同的圆角
        child: LinearProgressIndicator(
          value: progress, // 进度值
          backgroundColor: Colors.transparent, // 背景透明
          valueColor: AlwaysStoppedAnimation<Color>(color), // 进度条颜色
        ),
      ),
    );
  }
}
