Skip to content

Commit

Permalink
feat: added maxValue to progress circle
Browse files Browse the repository at this point in the history
  • Loading branch information
DE7924 committed Nov 5, 2024
1 parent bc5bcc0 commit f73a063
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/src/components/progress/progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -48,7 +55,7 @@ abstract class ZetaProgressState<T extends ZetaProgress> extends State<T> with T
).animate(controller)
..addListener(() {
setState(() {
progress = animation.value;
progress = animation.value / widget.maxValue;
});
});
}
Expand All @@ -65,10 +72,12 @@ abstract class ZetaProgressState<T extends ZetaProgress> extends State<T> with T

setState(() {
animation = Tween<double>(
begin: progress,
begin: progress * widget.maxValue,
end: newProgress,
).animate(controller);
controller.forward(from: progress);
controller
..reset()
..forward(from: 0);
});
}

Expand Down
15 changes: 13 additions & 2 deletions lib/src/components/progress/progress_circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,6 +61,7 @@ class ZetaProgressCircle extends ZetaProgress {
..add(DoubleProperty('progress', progress))
..add(DiagnosticsProperty<bool>('rounded', rounded))
..add(ObjectFlagProperty<VoidCallback?>.has('onCancel', onCancel))
..add(DoubleProperty('maxValue', maxValue))
..add(StringProperty('label', label));
}
}
Expand Down Expand Up @@ -108,6 +110,7 @@ class _ZetaProgressCircleState extends ZetaProgressState<ZetaProgressCircle> {
progress: animation.value,
rounded: context.rounded,
context: context,
maxValue: widget.maxValue,
),
child: Center(
child: widget.size == ZetaCircleSizes.xs
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
);
Expand Down

0 comments on commit f73a063

Please sign in to comment.