From e3d003eca13530cc4a3f16a666604a7009724a7e Mon Sep 17 00:00:00 2001 From: Daniel Eshkeri Date: Mon, 4 Nov 2024 13:44:55 +0000 Subject: [PATCH] feat: Added label prop to progress circle which overrides default percentage label --- .../pages/components/progress_example.dart | 1 + .../pages/components/progress_widgetbook.dart | 1 + .../components/progress/progress_circle.dart | 26 +++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/example/lib/pages/components/progress_example.dart b/example/lib/pages/components/progress_example.dart index 18309cb3..e20ad6df 100644 --- a/example/lib/pages/components/progress_example.dart +++ b/example/lib/pages/components/progress_example.dart @@ -132,6 +132,7 @@ class _WrapperState extends State { child: ZetaProgressCircle( progress: progress, size: widget.circleSize!, + label: '30%', ), ) : SizedBox( diff --git a/example/widgetbook/pages/components/progress_widgetbook.dart b/example/widgetbook/pages/components/progress_widgetbook.dart index 249b5896..ba643a22 100644 --- a/example/widgetbook/pages/components/progress_widgetbook.dart +++ b/example/widgetbook/pages/components/progress_widgetbook.dart @@ -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'), ), ); diff --git a/lib/src/components/progress/progress_circle.dart b/lib/src/components/progress/progress_circle.dart index 2538aafa..50383142 100644 --- a/lib/src/components/progress/progress_circle.dart +++ b/lib/src/components/progress/progress_circle.dart @@ -37,6 +37,7 @@ class ZetaProgressCircle extends ZetaProgress { this.size = ZetaCircleSizes.xl, super.rounded, this.onCancel, + this.label, }); ///Size of [ZetaProgressCircle] @@ -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 createState() => _ZetaProgressCircleState(); @@ -55,7 +59,8 @@ class ZetaProgressCircle extends ZetaProgress { ..add(EnumProperty('size', size)) ..add(DoubleProperty('progress', progress)) ..add(DiagnosticsProperty('rounded', rounded)) - ..add(ObjectFlagProperty.has('onCancel', onCancel)); + ..add(ObjectFlagProperty.has('onCancel', onCancel)) + ..add(StringProperty('label', label)); } } @@ -85,13 +90,11 @@ class _ZetaProgressCircleState extends ZetaProgressState { @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( @@ -168,6 +171,19 @@ class _ZetaProgressCircleState extends ZetaProgressState { } } + 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);