Skip to content

Commit 24490de

Browse files
committed
update version 2.0.0
1 parent 0c80e4c commit 24490de

7 files changed

Lines changed: 198 additions & 98 deletions

File tree

example/lib/main.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,13 @@ class _MyHomePageState extends State<MyHomePage> {
110110
),
111111
FlatButton(
112112
textColor: Colors.blue,
113-
child: Text('showProgress'),
113+
child: Text('showToast'),
114114
onPressed: () {
115-
_progress = 0;
116115
_timer?.cancel();
117-
_timer = Timer.periodic(const Duration(milliseconds: 100),
118-
(Timer timer) {
119-
EasyLoading.showProgress(_progress,
120-
status: '${(_progress * 100).toStringAsFixed(0)}%');
121-
_progress += 0.03;
122-
123-
if (_progress >= 1) {
124-
_timer?.cancel();
125-
EasyLoading.dismiss();
126-
}
127-
});
116+
EasyLoading.showToast(
117+
'Toast',
118+
toastPosition: EasyLoadingToastPosition.top,
119+
);
128120
},
129121
),
130122
FlatButton(
@@ -153,10 +145,21 @@ class _MyHomePageState extends State<MyHomePage> {
153145
),
154146
FlatButton(
155147
textColor: Colors.blue,
156-
child: Text('showToast'),
148+
child: Text('showProgress'),
157149
onPressed: () {
150+
_progress = 0;
158151
_timer?.cancel();
159-
EasyLoading.showToast('Toast');
152+
_timer = Timer.periodic(const Duration(milliseconds: 100),
153+
(Timer timer) {
154+
EasyLoading.showProgress(_progress,
155+
status: '${(_progress * 100).toStringAsFixed(0)}%');
156+
_progress += 0.03;
157+
158+
if (_progress >= 1) {
159+
_timer?.cancel();
160+
EasyLoading.dismiss();
161+
}
162+
});
160163
},
161164
),
162165
],
@@ -228,7 +231,10 @@ class _MyHomePageState extends State<MyHomePage> {
228231
),
229232
),
230233
Padding(
231-
padding: EdgeInsets.only(top: 20.0),
234+
padding: EdgeInsets.only(
235+
top: 20.0,
236+
bottom: 50.0,
237+
),
232238
child: Column(
233239
children: <Widget>[
234240
Text('IndicatorType(total: 23)'),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
typedef Widget OKToastAnimationBuilder(
4+
BuildContext context,
5+
Widget child,
6+
AnimationController controller,
7+
double percent,
8+
);
9+
10+
abstract class BaseAnimationBuilder {
11+
BaseAnimationBuilder();
12+
13+
Widget call(
14+
BuildContext context,
15+
Widget child,
16+
AnimationController controller,
17+
double percent,
18+
) {
19+
return buildWidget(context, child, controller, percent);
20+
}
21+
22+
Widget buildWidget(BuildContext context, Widget child,
23+
AnimationController controller, double percent);
24+
}

lib/src/easy_loading.dart

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ enum EasyLoadingStyle {
1414
custom,
1515
}
1616

17+
/// toast position
18+
enum EasyLoadingToastPosition {
19+
top,
20+
center,
21+
bottom,
22+
}
23+
24+
/// loading mask type
25+
/// [none] default mask type, allow user interactions while loading is displayed
26+
/// [clear] don't allow user interactions while loading is displayed
27+
/// [black] don't allow user interactions while loading is displayed
28+
/// [custom] while mask type is custom, maskColor should not be null
29+
enum EasyLoadingMaskType {
30+
none,
31+
clear,
32+
black,
33+
custom,
34+
}
35+
1736
/// loading indicator type. see [https://github.com/jogboms/flutter_spinkit#-showcase]
1837
enum EasyLoadingIndicatorType {
1938
fadingCircle,
@@ -41,18 +60,6 @@ enum EasyLoadingIndicatorType {
4160
squareCircle,
4261
}
4362

44-
/// loading mask type
45-
/// [none] default mask type, allow user interactions while loading is displayed
46-
/// [clear] don't allow user interactions while loading is displayed
47-
/// [black] don't allow user interactions while loading is displayed
48-
/// [custom] while mask type is custom, maskColor should not be null
49-
enum EasyLoadingMaskType {
50-
none,
51-
clear,
52-
black,
53-
custom,
54-
}
55-
5663
class EasyLoading {
5764
/// loading style, default [EasyLoadingStyle.dark].
5865
EasyLoadingStyle loadingStyle;
@@ -63,6 +70,9 @@ class EasyLoading {
6370
/// loading mask type, default [EasyLoadingMaskType.none].
6471
EasyLoadingMaskType maskType;
6572

73+
/// toast position, default [EasyLoadingToastPosition.center].
74+
EasyLoadingToastPosition toastPosition;
75+
6676
/// textAlign of status, default [TextAlign.center].
6777
TextAlign textAlign;
6878

@@ -126,13 +136,13 @@ class EasyLoading {
126136
OverlayEntry overlayEntry;
127137
Widget _w;
128138

129-
GlobalKey<LoadingContainerState> _key;
130-
GlobalKey<ProgressState> _progressKey;
139+
GlobalKey<EasyLoadingContainerState> _key;
140+
GlobalKey<EasyLoadingProgressState> _progressKey;
131141
Timer _timer;
132142

133143
Widget get w => _w;
134-
GlobalKey<LoadingContainerState> get key => _key;
135-
GlobalKey<ProgressState> get progressKey => _progressKey;
144+
GlobalKey<EasyLoadingContainerState> get key => _key;
145+
GlobalKey<EasyLoadingProgressState> get progressKey => _progressKey;
136146
Timer get timer => _timer;
137147

138148
factory EasyLoading() => _getInstance();
@@ -189,8 +199,9 @@ class EasyLoading {
189199
'progress value should be 0.0 ~ 1.0',
190200
);
191201
if (_getInstance()._progressKey == null || _getInstance().w == null) {
192-
GlobalKey<ProgressState> _progressKey = GlobalKey<ProgressState>();
193-
Widget w = Progress(
202+
GlobalKey<EasyLoadingProgressState> _progressKey =
203+
GlobalKey<EasyLoadingProgressState>();
204+
Widget w = EasyLoadingProgress(
194205
key: _progressKey,
195206
value: value,
196207
);
@@ -265,10 +276,12 @@ class EasyLoading {
265276
static void showToast(
266277
String status, {
267278
Duration duration,
279+
EasyLoadingToastPosition toastPosition,
268280
}) {
269281
_getInstance()._show(
270282
status: status,
271283
duration: duration ?? EasyLoadingTheme.displayDuration,
284+
toastPosition: toastPosition ?? EasyLoadingTheme.toastPosition,
272285
);
273286
}
274287

@@ -293,12 +306,18 @@ class EasyLoading {
293306
Widget w,
294307
String status,
295308
Duration duration,
309+
EasyLoadingToastPosition toastPosition = EasyLoadingToastPosition.center,
296310
}) {
297311
assert(
298312
_getInstance().overlayEntry != null,
299313
'overlayEntry should not be null',
300314
);
301315

316+
assert(
317+
toastPosition != null,
318+
'toastPosition should not be null',
319+
);
320+
302321
if (_getInstance().loadingStyle == EasyLoadingStyle.custom) {
303322
assert(
304323
_getInstance().backgroundColor != null,
@@ -328,12 +347,14 @@ class EasyLoading {
328347
_cancelTimer();
329348
_getInstance()._progressKey = null;
330349

331-
GlobalKey<LoadingContainerState> _key = GlobalKey<LoadingContainerState>();
332-
_getInstance()._w = LoadingContainer(
350+
GlobalKey<EasyLoadingContainerState> _key =
351+
GlobalKey<EasyLoadingContainerState>();
352+
_getInstance()._w = EasyLoadingContainer(
333353
key: _key,
334354
status: status,
335355
indicator: w,
336356
animation: _getInstance()._w == null,
357+
toastPosition: toastPosition,
337358
);
338359
_markNeedsBuild();
339360
_getInstance()._key = _key;
@@ -346,11 +367,11 @@ class EasyLoading {
346367

347368
void _dismiss(bool animation) {
348369
if (animation) {
349-
LoadingContainerState loadingContainerState =
370+
EasyLoadingContainerState easyLoadingContainerState =
350371
_getInstance().key?.currentState;
351-
if (loadingContainerState != null) {
372+
if (easyLoadingContainerState != null) {
352373
final Completer<void> completer = Completer<void>();
353-
loadingContainerState.dismiss(completer);
374+
easyLoadingContainerState.dismiss(completer);
354375
completer.future.then((value) {
355376
_reset();
356377
});

lib/src/theme.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
23
import './easy_loading.dart';
34

45
class EasyLoadingTheme {
@@ -58,6 +59,18 @@ class EasyLoadingTheme {
5859
static EasyLoadingIndicatorType get indicatorType =>
5960
EasyLoading.instance.indicatorType;
6061

62+
/// toast position
63+
static EasyLoadingToastPosition get toastPosition =>
64+
EasyLoading.instance.toastPosition;
65+
66+
/// toast position
67+
static AlignmentGeometry alignment(EasyLoadingToastPosition position) =>
68+
position == EasyLoadingToastPosition.bottom
69+
? AlignmentDirectional.bottomCenter
70+
: (position == EasyLoadingToastPosition.top
71+
? AlignmentDirectional.topCenter
72+
: AlignmentDirectional.center);
73+
6174
/// display duration
6275
static Duration get displayDuration => EasyLoading.instance.displayDuration;
6376

0 commit comments

Comments
 (0)