@@ -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}
0 commit comments