buildLoader method

  1. @override
Widget buildLoader(
  1. BuildContext context,
  2. AnimationController controller
)
override

Implementation

@override
Widget buildLoader(BuildContext context, AnimationController controller) {
  final double actualStrokeWidth = strokeWidth ?? size * 0.08;
  final double indicatorSize = size - actualStrokeWidth * 2;
  final animatedValue = progress ?? controller.value;

  return SizedBox(
    width: size,
    height: size,
    child: Stack(
      alignment: Alignment.center,
      children: [
        SizedBox(
          width: indicatorSize,
          height: indicatorSize,
          child: CircularProgressIndicator(
            value: loop ? null : animatedValue,
            strokeWidth: actualStrokeWidth,
            backgroundColor: backgroundColor?.withAlpha((0.2 * 255).toInt()),
            color: color ?? Colors.blue,
            strokeCap: strokeCap,
            valueColor: gradient != null
                ? AlwaysStoppedAnimation<Color>(gradient!.colors.first)
                : null,
          ),
        ),
        if (showPercentage)
          Text(
            "${(animatedValue * 100).toInt()}%",
            style: TextStyle(
              color: color ?? Colors.black,
              fontSize: indicatorSize * 0.3, // text scales with inner radius
              fontWeight: FontWeight.w600,
            ),
          ),
      ],
    ),
  );
}