Skip to content

Commit

Permalink
Respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Osman authored and Osman committed Feb 29, 2024
1 parent b2a229d commit 84b7541
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 94 deletions.
36 changes: 19 additions & 17 deletions example/lib/pages/components/progress_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ class ProgressExampleState extends State<ProgressExample> {
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 ...",
),
]),
Expand All @@ -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;

Expand All @@ -74,7 +74,7 @@ class Wrapper extends StatefulWidget {
class _WrapperState extends State<Wrapper> {
late int stepsCompleted;
late double progress;
late BarType type;
late ZetaBarType type;

@override
void initState() {
Expand All @@ -94,7 +94,9 @@ class _WrapperState extends State<Wrapper> {

void setLoading() {
setState(() {
type = type == BarType.buffering ? BarType.standard : BarType.buffering;
type = type == ZetaBarType.buffering
? ZetaBarType.standard
: ZetaBarType.buffering;
});
}

Expand All @@ -105,18 +107,18 @@ class _WrapperState extends State<Wrapper> {
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(),
Expand Down
20 changes: 10 additions & 10 deletions lib/src/components/progress/progress.dart
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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<T extends Progress> extends State<T>
abstract class ZetaProgressState<T extends ZetaProgress> extends State<T>
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<double> animation;

@override
Expand Down
113 changes: 46 additions & 67 deletions lib/src/components/progress/progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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<ZetaProgressBar> createState() => _ZetaProgressBarState();

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(EnumProperty<ZetaWidgetBorder>('border', border))
..add(EnumProperty<BarType>('type', type))
..add(EnumProperty<BarWeight>('weight', weight))
..add(StringProperty('label', label));
..add(DiagnosticsProperty<bool>('rounded', rounded))
..add(EnumProperty<ZetaBarType>('type', type))
..add(StringProperty('label', label))
..add(DiagnosticsProperty<bool>('isThin', isThin));
}
}

class _ProgressBarState extends ProgressState<ProgressBar> {
class _ZetaProgressBarState extends ZetaProgressState<ZetaProgressBar> {
@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,
),
),
Expand All @@ -125,38 +114,28 @@ class _ProgressBarState extends ProgressState<ProgressBar> {
}

/// 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<List<Widget>> extraList = List.filled(3, false).map((e) => [
const SizedBox(
width: 16,
),
Container(
width: _weight(),
height: _weight(),
width: _weight,
height: _weight,
decoration: const BoxDecoration(
color: Color.fromRGBO(224, 227, 233, 1),
borderRadius: ZetaRadius.rounded),
),
]);

final Widget extraWidgets = Row(
children: widget.type == BarType.buffering
children: widget.type == ZetaBarType.buffering
? extraList.expand((list) => list).toList()
: [],
);
Expand Down

0 comments on commit 84b7541

Please sign in to comment.