diff --git a/CHANGELOG.md b/CHANGELOG.md index bad3448..6d9fd3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [3.0.6] - 2022.08.13 + +* fixed [#178](https://github.com/nslogx/flutter_easyloading/issues/178) +* fixed [#178](https://github.com/nslogx/flutter_easyloading/issues/114) + ## [3.0.5] - 2022.05.23 * 🎉 It's support flutter 3.0 and previous version now @@ -108,4 +113,4 @@ ## [0.0.1] - 2019.12.23 -* init +* init \ No newline at end of file diff --git a/README-zh_CN.md b/README-zh_CN.md index a577290..3f04941 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -216,6 +216,8 @@ EasyLoading.instance 感谢 [flutter_spinkit](https://github.com/jogboms/flutter_spinkit) ❤️ +感谢 [back_button_interceptor](https://github.com/marcglasberg/back_button_interceptor) ❤️ + 感谢 [JetBrains Open Source](https://www.jetbrains.com/community/opensource/#support) 提供支持 -[](https://www.jetbrains.com/?from=FlutterEasyLoading) +[](https://www.jetbrains.com/?from=FlutterEasyLoading) \ No newline at end of file diff --git a/README.md b/README.md index bcaaaa6..a5126a3 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,8 @@ example: 👉 [Custom Animation](https://github.com/nslogx/flutter_easyloading/b Thanks to [flutter_spinkit](https://github.com/jogboms/flutter_spinkit) ❤️ +Thanks to [back_button_interceptor](https://github.com/marcglasberg/back_button_interceptor) ❤️ + Supported by [JetBrains Open Source](https://www.jetbrains.com/community/opensource/#support) [](https://www.jetbrains.com/?from=FlutterEasyLoading) - diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index 1193f48..89ac53c 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -24,6 +24,7 @@ import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; +import 'package:back_button_interceptor/back_button_interceptor.dart'; import './widgets/container.dart'; import './widgets/progress.dart'; @@ -253,6 +254,13 @@ class EasyLoading { bool? dismissOnTap, }) { Widget w = indicator ?? (_instance.indicatorWidget ?? LoadingIndicator()); + + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); + + if (isIgnoringBackButton) { + BackButtonInterceptor.add(_backButtonInterceptor); + } + return _instance._show( status: status, maskType: maskType, @@ -287,6 +295,12 @@ class EasyLoading { key: _progressKey, value: value, ); + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); + + if (isIgnoringBackButton) { + BackButtonInterceptor.add(_backButtonInterceptor); + } + _instance._show( status: status, maskType: maskType, @@ -390,7 +404,15 @@ class EasyLoading { }) { // cancel timer _instance._cancelTimer(); - return _instance._dismiss(animation); + return _instance._dismiss(animation).whenComplete( + () { + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(null); + + if (!isIgnoringBackButton) return; + + BackButtonInterceptor.remove(_backButtonInterceptor); + }, + ); } /// add loading status callback @@ -520,4 +542,10 @@ class EasyLoading { _timer?.cancel(); _timer = null; } + + static bool _backButtonInterceptor( + bool stopDefaultButtonEvent, + RouteInfo routeInfo, + ) => + true; } diff --git a/pubspec.yaml b/pubspec.yaml index e31e2ff..2ffdcc7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,13 @@ name: flutter_easyloading description: A clean and lightweight loading/toast widget for Flutter, Easy to use without context, Support iOS、Android and Web -version: 3.0.5 +version: 3.0.6 homepage: https://github.com/nslogx/flutter_easyloading environment: sdk: ">=2.12.0 <3.0.0" dependencies: + back_button_interceptor: ^6.0.1 flutter: sdk: flutter @@ -16,4 +17,4 @@ dev_dependencies: flutter_test: sdk: flutter -flutter: +flutter: \ No newline at end of file