Skip to content

Commit

Permalink
feat: Added label prop to progress circle which overrides default per…
Browse files Browse the repository at this point in the history
…centage label
  • Loading branch information
DE7924 committed Nov 4, 2024
1 parent 08382f6 commit e3d003e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions example/lib/pages/components/progress_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class _WrapperState extends State<Wrapper> {
child: ZetaProgressCircle(
progress: progress,
size: widget.circleSize!,
label: '30%',
),
)
: SizedBox(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ Widget progressCircleUseCase(BuildContext context) => WidgetbookScaffold(
labelBuilder: enumLabelBuilder,
),
onCancel: context.knobs.boolean(label: "Can Cancel") ? () {} : null,
label: context.knobs.stringOrNull(label: 'Label'),
),
);
26 changes: 21 additions & 5 deletions lib/src/components/progress/progress_circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ZetaProgressCircle extends ZetaProgress {
this.size = ZetaCircleSizes.xl,
super.rounded,
this.onCancel,
this.label,
});

///Size of [ZetaProgressCircle]
Expand All @@ -45,6 +46,9 @@ class ZetaProgressCircle extends ZetaProgress {
/// Cancel function => cancel upload.
final VoidCallback? onCancel;

/// Label for [ZetaProgressCircle], override default percentage label.
final String? label;

@override
State<ZetaProgressCircle> createState() => _ZetaProgressCircleState();

Expand All @@ -55,7 +59,8 @@ class ZetaProgressCircle extends ZetaProgress {
..add(EnumProperty<ZetaCircleSizes>('size', size))
..add(DoubleProperty('progress', progress))
..add(DiagnosticsProperty<bool>('rounded', rounded))
..add(ObjectFlagProperty<VoidCallback?>.has('onCancel', onCancel));
..add(ObjectFlagProperty<VoidCallback?>.has('onCancel', onCancel))
..add(StringProperty('label', label));
}
}

Expand Down Expand Up @@ -85,13 +90,11 @@ class _ZetaProgressCircleState extends ZetaProgressState<ZetaProgressCircle> {

@override
Widget build(BuildContext context) {
final textVal = '${(widget.progress * 100).round()}%';
final textVal = widget.label ?? '${(widget.progress * 100).round()}%';
final colors = Zeta.of(context).colors;
final textWidget = Text(
textVal,
style: widget.size != ZetaCircleSizes.s
? ZetaTextStyles.labelSmall
: ZetaTextStyles.labelSmall.copyWith(fontSize: Zeta.of(context).spacing.small),
style: _getTextSize(),
);

return ConstrainedBox(
Expand Down Expand Up @@ -168,6 +171,19 @@ class _ZetaProgressCircleState extends ZetaProgressState<ZetaProgressCircle> {
}
}

TextStyle _getTextSize() {
switch (widget.size) {
case ZetaCircleSizes.xs:
case ZetaCircleSizes.s:
return ZetaTextStyles.labelSmall;
case ZetaCircleSizes.m:
return ZetaTextStyles.labelMedium;
case ZetaCircleSizes.l:
case ZetaCircleSizes.xl:
return ZetaTextStyles.labelLarge;
}
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down

0 comments on commit e3d003e

Please sign in to comment.