Skip to content

Commit 57011bd

Browse files
committed
fixed #58
1 parent 95541ab commit 57011bd

4 files changed

Lines changed: 37 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.0.1] - 2020.11.06
2+
3+
* fixed [#58](https://github.com/huangjianke/flutter_easyloading/issues/58)
4+
15
## [2.0.0] - 2020.09.28
26

37
* add custom animation style

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ packages:
8282
path: ".."
8383
relative: true
8484
source: path
85-
version: "2.0.0"
85+
version: "2.0.1"
8686
flutter_spinkit:
8787
dependency: transitive
8888
description:

lib/src/easy_loading.dart

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ class EasyLoading {
157157
GlobalKey<EasyLoadingContainerState> _key;
158158
GlobalKey<EasyLoadingProgressState> _progressKey;
159159
Timer _timer;
160+
Completer<void> _completer;
160161

161162
Widget get w => _w;
162163
GlobalKey<EasyLoadingContainerState> get key => _key;
163164
GlobalKey<EasyLoadingProgressState> get progressKey => _progressKey;
164-
Timer get timer => _timer;
165165

166166
factory EasyLoading() => _getInstance();
167167
static EasyLoading _instance;
@@ -323,7 +323,7 @@ class EasyLoading {
323323
EasyLoadingToastPosition toastPosition = EasyLoadingToastPosition.center,
324324
}) {
325325
assert(
326-
_getInstance().overlayEntry != null,
326+
overlayEntry != null,
327327
'overlayEntry should not be null',
328328
);
329329

@@ -332,69 +332,69 @@ class EasyLoading {
332332
'toastPosition should not be null',
333333
);
334334

335-
if (_getInstance().loadingStyle == EasyLoadingStyle.custom) {
335+
if (loadingStyle == EasyLoadingStyle.custom) {
336336
assert(
337-
_getInstance().backgroundColor != null,
337+
backgroundColor != null,
338338
'while loading style is custom, backgroundColor should not be null',
339339
);
340340
assert(
341-
_getInstance().indicatorColor != null,
341+
indicatorColor != null,
342342
'while loading style is custom, indicatorColor should not be null',
343343
);
344344
assert(
345-
_getInstance().progressColor != null,
345+
progressColor != null,
346346
'while loading style is custom, progressColor should not be null',
347347
);
348348
assert(
349-
_getInstance().textColor != null,
349+
textColor != null,
350350
'while loading style is custom, textColor should not be null',
351351
);
352352
}
353353

354-
if (_getInstance().maskType == EasyLoadingMaskType.custom) {
354+
if (maskType == EasyLoadingMaskType.custom) {
355355
assert(
356-
_getInstance().maskColor != null,
356+
maskColor != null,
357357
'while mask type is custom, maskColor should not be null',
358358
);
359359
}
360360

361-
if (_getInstance().animationStyle == EasyLoadingAnimationStyle.custom) {
361+
if (animationStyle == EasyLoadingAnimationStyle.custom) {
362362
assert(
363-
_getInstance().customAnimation != null,
363+
customAnimation != null,
364364
'while animationStyle is custom, customAnimation should not be null',
365365
);
366366
}
367367

368368
_cancelTimer();
369-
_getInstance()._progressKey = null;
369+
_progressKey = null;
370+
if (_completer?.isCompleted == false) _completer = null;
370371

371-
GlobalKey<EasyLoadingContainerState> _key =
372+
GlobalKey<EasyLoadingContainerState> _containerKey =
372373
GlobalKey<EasyLoadingContainerState>();
373-
_getInstance()._w = EasyLoadingContainer(
374-
key: _key,
374+
_w = EasyLoadingContainer(
375+
key: _containerKey,
375376
status: status,
376377
indicator: w,
377378
animation: _getInstance()._w == null,
378379
toastPosition: toastPosition,
379380
);
380381
_markNeedsBuild();
381-
_getInstance()._key = _key;
382+
_key = _containerKey;
382383
if (duration != null) {
383-
_getInstance()._timer = Timer.periodic(duration, (Timer timer) {
384+
_timer = Timer.periodic(duration, (Timer timer) {
384385
dismiss();
385386
});
386387
}
387388
}
388389

389390
void _dismiss(bool animation) {
390391
if (animation) {
391-
EasyLoadingContainerState easyLoadingContainerState =
392-
_getInstance().key?.currentState;
392+
EasyLoadingContainerState easyLoadingContainerState = key?.currentState;
393393
if (easyLoadingContainerState != null) {
394-
final Completer<void> completer = Completer<void>();
395-
easyLoadingContainerState.dismiss(completer);
396-
completer.future.then((value) {
397-
_reset();
394+
_completer = Completer<void>();
395+
easyLoadingContainerState.dismiss(_completer);
396+
_completer?.future?.then((value) {
397+
if (_completer != null) _reset();
398398
});
399399
return;
400400
}
@@ -403,18 +403,19 @@ class EasyLoading {
403403
}
404404

405405
void _reset() {
406-
_getInstance()._w = null;
407-
_getInstance()._key = null;
408-
_getInstance()._progressKey = null;
406+
_w = null;
407+
_key = null;
408+
_progressKey = null;
409+
_completer = null;
409410
_markNeedsBuild();
410411
}
411412

412413
void _markNeedsBuild() {
413-
_getInstance().overlayEntry?.markNeedsBuild();
414+
overlayEntry?.markNeedsBuild();
414415
}
415416

416417
void _cancelTimer() {
417-
_getInstance().timer?.cancel();
418-
_getInstance()._timer = null;
418+
_timer?.cancel();
419+
_timer = null;
419420
}
420421
}

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_easyloading
2-
description: A clean and lightweight Loading widget for Flutter App, easy to use without context, support iOS、Android and Web.
3-
version: 2.0.0
2+
description: A clean and lightweight Loading widget for Flutter, easy to use without context, support iOS、Android and Web.
3+
version: 2.0.1
44
homepage: https://github.com/huangjianke/flutter_easyloading
55

66
environment:

0 commit comments

Comments
 (0)