-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.dart
218 lines (200 loc) · 6.48 KB
/
main.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import 'package:flutter/material.dart';
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
void main() {
runApp(MyExample());
}
class MyExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Home(),
);
}
}
class Home extends StatelessWidget {
_normalProgress(context) async {
/// Create progress dialog
ProgressDialog pd = ProgressDialog(context: context);
/// Set options
/// Max and msg required
pd.show(
max: 100,
msg: 'File Downloading...',
progressBgColor: Colors.transparent,
cancel: Cancel(
cancelClicked: () {
/// ex: cancel the download
},
),
);
for (int i = 0; i <= 100; i++) {
/// You don't need to update state, just pass the value.
pd.update(value: i);
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}
/// Shows a progress dialog with a determinate progress bar.
_valuableProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
max: 100,
msg: 'File Downloading...',
progressType: ProgressType.valuable,
);
for (int i = 0; i <= 100; i++) {
pd.update(value: i);
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}
/// Shows a progress dialog that starts with a preparation message,
/// then switches to a downloading message.
_preparingProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
max: 100,
msg: 'Preparing Download...',
progressType: ProgressType.determinate,
);
await Future.delayed(Duration(milliseconds: 3000));
for (int i = 0; i <= 100; i++) {
pd.update(value: i, msg: 'File Downloading...');
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}
/// Shows a customizable progress dialog with a dark theme.
_customProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
max: 100,
msg: 'Preparing Download...',
progressType: ProgressType.determinate,
backgroundColor: Color(0xff212121),
progressValueColor: Color(0xff3550B4),
progressBgColor: Colors.white70,
msgColor: Colors.white,
valueColor: Colors.white);
await Future.delayed(Duration(milliseconds: 3000));
for (int i = 0; i <= 100; i++) {
pd.update(value: i, msg: 'File Downloading...');
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}
/// Shows a progress dialog that completes with a custom completion widget.
_completedProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
max: 100,
msg: 'File Downloading...',
completed: Completed(),
// Completed values can be customized
// Completed(completedMsg: "Downloading Done !", completedImage: AssetImage("images/completed.png"), completionDelay: 2500,),
progressBgColor: Colors.transparent,
);
for (int i = 0; i <= 100; i++) {
pd.update(value: i);
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}
/// Shows a message-only progress dialog without a progress bar.
_onlyMessageProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
barrierDismissible: true,
msg: "Please waiting...",
hideValue: true,
);
await Future.delayed(Duration(milliseconds: 1000));
pd.update(msg: "Almost done...");
await Future.delayed(Duration(milliseconds: 1000));
pd.close();
}
/// Shows a message-only progress dialog that completes automatically.
_onlyMessageWithCompletionProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
barrierDismissible: true,
msg: "Please waiting...",
hideValue: true,
completed: Completed(completionDelay: 1500), // Set Completed
);
await Future.delayed(Duration(milliseconds: 1000));
pd.update(msg: "Almost done...");
await Future.delayed(Duration(milliseconds: 1000));
/**
* if you can't assign value and want to use completed object. You should set the Value to 100.
* The dialog will close automatically.
* **/
pd.update(value: 100);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
'Sn Progress Example',
style: TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
),
),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Normal Progress'),
onPressed: () {
_normalProgress(context);
}),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Valuable Progress'),
onPressed: () {
_valuableProgress(context);
}),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Preparing Progress'),
onPressed: () {
_preparingProgress(context);
}),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Custom Progress'),
onPressed: () {
_customProgress(context);
}),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Completed Progress'),
onPressed: () {
_completedProgress(context);
}),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Message Progress'),
onPressed: () {
_onlyMessageProgress(context);
}),
MaterialButton(
color: Color(0xfff7f7f7),
child: Text('Message Progress With Completed'),
onPressed: () {
_onlyMessageWithCompletionProgress(context);
}),
],
),
),
),
);
}
}