diff --git a/example/lib/pages/components/progress_example.dart b/example/lib/pages/components/progress_example.dart index 69b31456..84167758 100644 --- a/example/lib/pages/components/progress_example.dart +++ b/example/lib/pages/components/progress_example.dart @@ -23,23 +23,23 @@ class ProgressExampleState extends State { child: Column(children: [ Wrapper( stepsCompleted: 10, - weight: BarWeight.thin, + isThin: true, ), SizedBox( height: 20, ), Wrapper( stepsCompleted: 0, - type: BarType.standard, - weight: BarWeight.thin, + type: ZetaBarType.standard, + isThin: false, stateChangeable: true), SizedBox( height: 20, ), Wrapper( stepsCompleted: 0, - type: BarType.indeterminate, - weight: BarWeight.medium, + type: ZetaBarType.indeterminate, + isThin: false, label: "UPLOADING ...", ), ]), @@ -54,16 +54,16 @@ class Wrapper extends StatefulWidget { const Wrapper( {super.key, required this.stepsCompleted, - this.type = BarType.standard, - this.weight = BarWeight.medium, - this.border = ZetaWidgetBorder.rounded, + this.type = ZetaBarType.standard, + this.isThin = false, + this.rounded = true, this.stateChangeable = false, this.label}); final int stepsCompleted; - final ZetaWidgetBorder border; - final BarType type; - final BarWeight weight; + final bool rounded; + final ZetaBarType type; + final bool isThin; final String? label; final bool stateChangeable; @@ -74,7 +74,7 @@ class Wrapper extends StatefulWidget { class _WrapperState extends State { late int stepsCompleted; late double progress; - late BarType type; + late ZetaBarType type; @override void initState() { @@ -94,7 +94,9 @@ class _WrapperState extends State { void setLoading() { setState(() { - type = type == BarType.buffering ? BarType.standard : BarType.buffering; + type = type == ZetaBarType.buffering + ? ZetaBarType.standard + : ZetaBarType.buffering; }); } @@ -105,18 +107,18 @@ class _WrapperState extends State { children: [ SizedBox( width: 400, - child: ProgressBar( + child: ZetaProgressBar( progress: progress, - border: widget.border, + rounded: widget.rounded, type: type, - weight: widget.weight, + isThin: widget.isThin, label: widget.label), ), const SizedBox(width: 40), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - widget.type != BarType.indeterminate + widget.type != ZetaBarType.indeterminate ? FilledButton( onPressed: increasePercentage, child: Text("Increase")) : Container(), diff --git a/lib/src/components/progress/progress.dart b/lib/src/components/progress/progress.dart index 278ab442..8730a303 100644 --- a/lib/src/components/progress/progress.dart +++ b/lib/src/components/progress/progress.dart @@ -1,13 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -/// Super class for [Progress] widgets. -/// Handles state for progress of [Progress] widgets. -abstract class Progress extends StatefulWidget { - /// Constructor for abstract [Progress] class. - const Progress({super.key, this.progress = 0}); +/// Super class for [ZetaProgress] widgets. +/// Handles state for progress of [ZetaProgress] widgets. +abstract class ZetaProgress extends StatefulWidget { + /// Constructor for abstract [ZetaProgress] class. + const ZetaProgress({super.key, this.progress = 0}); - /// Progress value, decimal value ranging from 0.0 - 1.0, 0.5 = 50% + /// ZetaProgress value, decimal value ranging from 0.0 - 1.0, 0.5 = 50% final double progress; @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { @@ -16,18 +16,18 @@ abstract class Progress extends StatefulWidget { } } -/// Super class for [ProgressState] +/// Super class for [ZetaProgressState] /// Defines functions that deal with state change of progress value and /// animation changing. -abstract class ProgressState extends State +abstract class ZetaProgressState extends State with TickerProviderStateMixin { /// Decimal progress value late double progress; - ///Animation controller for [ProgressState] + ///Animation controller for [ZetaProgressState] late AnimationController controller; - ///Animation for [ProgressState] + ///Animation for [ZetaProgressState] late Animation animation; @override diff --git a/lib/src/components/progress/progress_bar.dart b/lib/src/components/progress/progress_bar.dart index 488ed621..f7793fc8 100644 --- a/lib/src/components/progress/progress_bar.dart +++ b/lib/src/components/progress/progress_bar.dart @@ -4,7 +4,7 @@ import '../../../zeta_flutter.dart'; import 'progress.dart'; /// Enum for types of progress bar -enum BarType { +enum ZetaBarType { /// Standard bar type. standard, @@ -15,105 +15,94 @@ enum BarType { buffering } -/// BarWeight of progress bar -enum BarWeight { - /// Thin weight. - thin, - - ///Medium weight - medium -} - /// Linear progress bar. /// Uses progress percentage value to fill bar -class ProgressBar extends Progress { - ///Constructor for [ProgressBar] +class ZetaProgressBar extends ZetaProgress { + ///Constructor for [ZetaProgressBar] - const ProgressBar( + const ZetaProgressBar( {super.key, required super.progress, - required this.border, + required this.rounded, required this.type, - required this.weight, + required this.isThin, this.label}); /// Constructs a standard progress bar - const ProgressBar.standard( + const ZetaProgressBar.standard( {super.key, required super.progress, - this.border = ZetaWidgetBorder.rounded, - this.type = BarType.standard, - this.weight = BarWeight.medium, - this.label}); + this.rounded = true, + this.isThin = false, + this.label}) + : type = ZetaBarType.standard; /// Constructs buffering example - const ProgressBar.buffering( + const ZetaProgressBar.buffering( {super.key, required super.progress, - this.border = ZetaWidgetBorder.rounded, - this.type = BarType.buffering, - this.weight = BarWeight.medium, - this.label}); + this.rounded = true, + this.isThin = false, + this.label}) + : type = ZetaBarType.buffering; /// Constructs indeterminate example - const ProgressBar.indeterminate( + const ZetaProgressBar.indeterminate( {super.key, required super.progress, - this.border = ZetaWidgetBorder.rounded, - this.type = BarType.indeterminate, - this.weight = BarWeight.medium, - this.label}); + this.rounded = true, + this.isThin = false, + this.label}) + : type = ZetaBarType.indeterminate; - /// Border type of the progress bar. - final ZetaWidgetBorder border; + /// Is progress bar rounded or sharp. + final bool rounded; /// Type of the progress bar. - final BarType type; + final ZetaBarType type; - /// Weight of progress bar to determine its thickness. - final BarWeight weight; + /// Is Progress bar thin or thick. + final bool isThin; ///Optional label final String? label; @override - _ProgressBarState createState() => _ProgressBarState(); + State createState() => _ZetaProgressBarState(); @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(EnumProperty('border', border)) - ..add(EnumProperty('type', type)) - ..add(EnumProperty('weight', weight)) - ..add(StringProperty('label', label)); + ..add(DiagnosticsProperty('rounded', rounded)) + ..add(EnumProperty('type', type)) + ..add(StringProperty('label', label)) + ..add(DiagnosticsProperty('isThin', isThin)); } } -class _ProgressBarState extends ProgressState { +class _ZetaProgressBarState extends ZetaProgressState { @override Widget build(BuildContext context) { return Column( children: [ if (widget.label != null) - SizedBox( - child: Text( - widget.label!, - textAlign: TextAlign.start, - ), + Text( + widget.label!, + textAlign: TextAlign.start, ), Row(crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: AnimatedContainer( duration: const Duration(milliseconds: 500), - height: _weight(), + height: _weight, child: LinearProgressIndicator( - borderRadius: _border(), - value: widget.type == BarType.indeterminate + borderRadius: _border, + value: widget.type == ZetaBarType.indeterminate ? null : animation.value, - backgroundColor: widget.type == BarType.buffering - ? const Color.fromRGBO(224, 227, 233, 1) + backgroundColor: widget.type == ZetaBarType.buffering + ? Zeta.of(context).colors.surfaceDisabled : Colors.transparent, ), ), @@ -125,21 +114,11 @@ class _ProgressBarState extends ProgressState { } /// Returns border based on widgets border type. - BorderRadius _border() { - return BorderRadius.all(widget.border == ZetaWidgetBorder.rounded - ? const Radius.circular(12) - : Radius.zero); - } + BorderRadius get _border => + widget.rounded ? ZetaRadius.rounded : ZetaRadius.none; /// Returns thickness of progress bar based on its weight. - double _weight() { - switch (widget.weight) { - case BarWeight.medium: - return 16; - case BarWeight.thin: - return 8; - } - } + double get _weight => widget.isThin ? 8 : 16; Widget _extraWidgets() { final Iterable> extraList = List.filled(3, false).map((e) => [ @@ -147,8 +126,8 @@ class _ProgressBarState extends ProgressState { width: 16, ), Container( - width: _weight(), - height: _weight(), + width: _weight, + height: _weight, decoration: const BoxDecoration( color: Color.fromRGBO(224, 227, 233, 1), borderRadius: ZetaRadius.rounded), @@ -156,7 +135,7 @@ class _ProgressBarState extends ProgressState { ]); final Widget extraWidgets = Row( - children: widget.type == BarType.buffering + children: widget.type == ZetaBarType.buffering ? extraList.expand((list) => list).toList() : [], );