forked from ZebraDevs/zeta_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_example.dart
166 lines (154 loc) · 4.33 KB
/
progress_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
class ProgressExample extends StatefulWidget {
static const String name = 'Progress';
const ProgressExample({super.key});
@override
State<ProgressExample> createState() => ProgressExampleState();
}
class ProgressExampleState extends State<ProgressExample> {
@override
Widget build(BuildContext context) {
return ExampleScaffold(
name: 'Progress',
child: Center(
child: SingleChildScrollView(
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Text('Progress Bars', style: ZetaTextStyles.displayMedium),
SizedBox(
height: 20,
),
Wrapper(
stepsCompleted: 10,
isThin: true,
),
SizedBox(
height: 20,
),
Wrapper(
stepsCompleted: 0,
type: ZetaBarType.standard,
isThin: false,
stateChangeable: true),
SizedBox(
height: 20,
),
Wrapper(
stepsCompleted: 0,
type: ZetaBarType.indeterminate,
isThin: false,
label: "UPLOADING ...",
),
SizedBox(
height: 20,
),
Text('Progress CIrcles', style: ZetaTextStyles.displayMedium),
SizedBox(
height: 80,
),
Wrapper(
stepsCompleted: 0,
circleSize: ZetaCircleSizes.xl,
rounded: false,
isCircle: true,
),
],
),
),
),
),
);
}
}
class Wrapper extends StatefulWidget {
const Wrapper({
super.key,
required this.stepsCompleted,
this.type = ZetaBarType.standard,
this.isThin = false,
this.rounded = true,
this.stateChangeable = false,
this.label,
this.isCircle = false,
this.circleSize,
});
final int stepsCompleted;
final bool? rounded;
final ZetaBarType? type;
final bool? isThin;
final String? label;
final bool? stateChangeable;
final bool isCircle;
final ZetaCircleSizes? circleSize;
@override
State<Wrapper> createState() => _WrapperState();
}
class _WrapperState extends State<Wrapper> {
late int stepsCompleted;
late double progress;
late ZetaBarType type;
@override
void initState() {
super.initState();
type = widget.type!;
stepsCompleted = widget.stepsCompleted;
progress = stepsCompleted / 10;
}
///Function to increase percentage of progress.
void increasePercentage() {
setState(() {
stepsCompleted++;
progress = stepsCompleted / 10;
});
}
void setLoading() {
setState(() {
type = type == ZetaBarType.buffering
? ZetaBarType.standard
: ZetaBarType.buffering;
});
}
@override
Widget build(BuildContext context) {
return Column(
// Replace with a Column for vertical
children: [
widget.isCircle
? Center(
child: ZetaProgressCircle(
progress: progress,
size: widget.circleSize!,
),
)
: SizedBox(
width: 400,
child: ZetaProgressBar(
progress: progress,
rounded: widget.rounded!,
type: type,
isThin: widget.isThin!,
label: widget.label),
),
const SizedBox(width: 40),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
widget.type != ZetaBarType.indeterminate
? FilledButton(
onPressed: increasePercentage, child: Text("Increase"))
: Container(),
const SizedBox(width: 40),
widget.stateChangeable!
? FilledButton(
onPressed: setLoading, child: Text("Start Buffering"))
: SizedBox.shrink()
],
)
],
);
}
}