@@ -24,6 +24,7 @@ import 'dart:async';
24
24
import 'dart:math' ;
25
25
26
26
import 'package:flutter/material.dart' ;
27
+ import 'package:back_button_interceptor/back_button_interceptor.dart' ;
27
28
28
29
import './widgets/container.dart' ;
29
30
import './widgets/progress.dart' ;
@@ -253,6 +254,13 @@ class EasyLoading {
253
254
bool ? dismissOnTap,
254
255
}) {
255
256
Widget w = indicator ?? (_instance.indicatorWidget ?? LoadingIndicator ());
257
+
258
+ final isIgnoringBackButton = ! EasyLoadingTheme .ignoring (maskType);
259
+
260
+ if (isIgnoringBackButton) {
261
+ BackButtonInterceptor .add (_backButtonInterceptor);
262
+ }
263
+
256
264
return _instance._show (
257
265
status: status,
258
266
maskType: maskType,
@@ -287,6 +295,12 @@ class EasyLoading {
287
295
key: _progressKey,
288
296
value: value,
289
297
);
298
+ final isIgnoringBackButton = ! EasyLoadingTheme .ignoring (maskType);
299
+
300
+ if (isIgnoringBackButton) {
301
+ BackButtonInterceptor .add (_backButtonInterceptor);
302
+ }
303
+
290
304
_instance._show (
291
305
status: status,
292
306
maskType: maskType,
@@ -390,7 +404,15 @@ class EasyLoading {
390
404
}) {
391
405
// cancel timer
392
406
_instance._cancelTimer ();
393
- return _instance._dismiss (animation);
407
+ return _instance._dismiss (animation).whenComplete (
408
+ () {
409
+ final isIgnoringBackButton = ! EasyLoadingTheme .ignoring (null );
410
+
411
+ if (! isIgnoringBackButton) return ;
412
+
413
+ BackButtonInterceptor .remove (_backButtonInterceptor);
414
+ },
415
+ );
394
416
}
395
417
396
418
/// add loading status callback
@@ -520,4 +542,10 @@ class EasyLoading {
520
542
_timer? .cancel ();
521
543
_timer = null ;
522
544
}
545
+
546
+ static bool _backButtonInterceptor (
547
+ bool stopDefaultButtonEvent,
548
+ RouteInfo routeInfo,
549
+ ) =>
550
+ true ;
523
551
}
0 commit comments