From f73a0636ce4dd8bb741e0e92c2d81ba6f4139173 Mon Sep 17 00:00:00 2001 From: Daniel Eshkeri Date: Tue, 5 Nov 2024 15:27:01 +0000 Subject: [PATCH] feat: added maxValue to progress circle --- lib/src/components/progress/progress.dart | 17 +++++++++++++---- .../components/progress/progress_circle.dart | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/src/components/progress/progress.dart b/lib/src/components/progress/progress.dart index 0ffa2f14..42bb92a0 100644 --- a/lib/src/components/progress/progress.dart +++ b/lib/src/components/progress/progress.dart @@ -10,14 +10,21 @@ abstract class ZetaProgress extends ZetaStatefulWidget { super.key, super.rounded, this.progress = 0, + this.maxValue = 1, }); /// ZetaProgress value, decimal value ranging from 0.0 - 1.0, 0.5 = 50% final double progress; + + /// Maximum value for progress, defaults to 1 + final double maxValue; + @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DoubleProperty('progress', progress)); + properties + ..add(DoubleProperty('progress', progress)) + ..add(DoubleProperty('maxValue', maxValue)); } } @@ -48,7 +55,7 @@ abstract class ZetaProgressState extends State with T ).animate(controller) ..addListener(() { setState(() { - progress = animation.value; + progress = animation.value / widget.maxValue; }); }); } @@ -65,10 +72,12 @@ abstract class ZetaProgressState extends State with T setState(() { animation = Tween( - begin: progress, + begin: progress * widget.maxValue, end: newProgress, ).animate(controller); - controller.forward(from: progress); + controller + ..reset() + ..forward(from: 0); }); } diff --git a/lib/src/components/progress/progress_circle.dart b/lib/src/components/progress/progress_circle.dart index 50383142..6847e401 100644 --- a/lib/src/components/progress/progress_circle.dart +++ b/lib/src/components/progress/progress_circle.dart @@ -34,6 +34,7 @@ class ZetaProgressCircle extends ZetaProgress { const ZetaProgressCircle({ super.key, super.progress = 0, + super.maxValue = 1, this.size = ZetaCircleSizes.xl, super.rounded, this.onCancel, @@ -60,6 +61,7 @@ class ZetaProgressCircle extends ZetaProgress { ..add(DoubleProperty('progress', progress)) ..add(DiagnosticsProperty('rounded', rounded)) ..add(ObjectFlagProperty.has('onCancel', onCancel)) + ..add(DoubleProperty('maxValue', maxValue)) ..add(StringProperty('label', label)); } } @@ -108,6 +110,7 @@ class _ZetaProgressCircleState extends ZetaProgressState { progress: animation.value, rounded: context.rounded, context: context, + maxValue: widget.maxValue, ), child: Center( child: widget.size == ZetaCircleSizes.xs @@ -201,7 +204,12 @@ typedef CirclePainter = _CirclePainter; /// Class definition for [_CirclePainter] class _CirclePainter extends CustomPainter { ///Constructor for [_CirclePainter] - _CirclePainter({this.progress = 0, this.rounded = true, required this.context}); + _CirclePainter({ + this.progress = 0, + this.rounded = true, + required this.context, + this.maxValue = 1, + }); ///Percentage of progress in decimal value, defaults to 0 final double progress; @@ -211,6 +219,9 @@ class _CirclePainter extends CustomPainter { final BuildContext context; + /// Maximum value for progress, defaults to 1 + final double maxValue; + final _paint = Paint(); @override @@ -226,7 +237,7 @@ class _CirclePainter extends CustomPainter { canvas.drawArc( Rect.fromLTRB(0, 0, size.width, size.height), 3 * math.pi / 2, - progress * fullCircle, + progress / maxValue * fullCircle, false, _paint, );