From 2823b8d10e8c7a92bd5c638f6311f7a9044e6e60 Mon Sep 17 00:00:00 2001 From: Fedor Blagodyr Date: Sat, 13 Aug 2022 15:53:41 +0300 Subject: [PATCH 1/6] feat(back_button): Added back button interceptor Added BackButtonInterceptor package, so if it's declared no userInteractions, there will be no route popping --- lib/src/easy_loading.dart | 34 +++++++++++++++++++++++++++------- pubspec.yaml | 1 + 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index 1193f48..c40e626 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,12 +254,23 @@ class EasyLoading { bool? dismissOnTap, }) { Widget w = indicator ?? (_instance.indicatorWidget ?? LoadingIndicator()); - return _instance._show( - status: status, - maskType: maskType, - dismissOnTap: dismissOnTap, - w: w, - ); + showFunc() => _instance._show( + status: status, + maskType: maskType, + dismissOnTap: dismissOnTap, + w: w, + ); + + final isIgnoring = EasyLoadingTheme.ignoring(maskType); + + if (!isIgnoring) return showFunc(); + + BackButtonInterceptor.add(_backButtonInterceptor); + + return (dismissOnTap ?? false) + ? showFunc().whenComplete( + () => BackButtonInterceptor.remove(_backButtonInterceptor)) + : showFunc(); } /// show progress with [value] [status] [maskType], value should be 0.0 ~ 1.0. @@ -390,7 +402,9 @@ class EasyLoading { }) { // cancel timer _instance._cancelTimer(); - return _instance._dismiss(animation); + return _instance._dismiss(animation).whenComplete( + () => BackButtonInterceptor.remove(_backButtonInterceptor), + ); } /// add loading status callback @@ -520,4 +534,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..058bbe1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,6 +7,7 @@ environment: sdk: ">=2.12.0 <3.0.0" dependencies: + back_button_interceptor: ^6.0.1 flutter: sdk: flutter From ccc9fbed02003ab380dc180705d90f6bca4064e7 Mon Sep 17 00:00:00 2001 From: Fedor Blagodyr Date: Sat, 13 Aug 2022 16:20:34 +0300 Subject: [PATCH 2/6] feat(back_button): Some improvements Added same logic for showProgress Readme, changelog upd --- CHANGELOG.md | 5 +++++ README-zh_CN.md | 2 ++ README.md | 2 ++ lib/src/easy_loading.dart | 21 +++++++++++++++------ pubspec.yaml | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bad3448..8e59276 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 diff --git a/README-zh_CN.md b/README-zh_CN.md index a577290..76b0ba4 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) diff --git a/README.md b/README.md index bcaaaa6..292771f 100644 --- a/README.md +++ b/README.md @@ -217,6 +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 c40e626..95ddd95 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -299,12 +299,21 @@ class EasyLoading { key: _progressKey, value: value, ); - _instance._show( - status: status, - maskType: maskType, - dismissOnTap: false, - w: w, - ); + + final isIgnoring = EasyLoadingTheme.ignoring(maskType); + + if (isIgnoring) BackButtonInterceptor.add(_backButtonInterceptor); + + _instance + ._show( + status: status, + maskType: maskType, + dismissOnTap: false, + w: w, + ) + .whenComplete( + () => BackButtonInterceptor.remove(_backButtonInterceptor), + ); _instance._progressKey = _progressKey; } // update progress diff --git a/pubspec.yaml b/pubspec.yaml index 058bbe1..e0c77f0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ 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: From c0f2eb8489dd8b5e78078ef191515733706d5aa1 Mon Sep 17 00:00:00 2001 From: Fedor Blagodyr Date: Sat, 13 Aug 2022 16:31:59 +0300 Subject: [PATCH 3/6] fix(back_button): Some logic fixes --- lib/src/easy_loading.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index 95ddd95..76b6598 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -261,9 +261,9 @@ class EasyLoading { w: w, ); - final isIgnoring = EasyLoadingTheme.ignoring(maskType); + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); - if (!isIgnoring) return showFunc(); + if (!isIgnoringBackButton) return showFunc(); BackButtonInterceptor.add(_backButtonInterceptor); @@ -300,9 +300,10 @@ class EasyLoading { value: value, ); - final isIgnoring = EasyLoadingTheme.ignoring(maskType); + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); - if (isIgnoring) BackButtonInterceptor.add(_backButtonInterceptor); + if (isIgnoringBackButton) + BackButtonInterceptor.add(_backButtonInterceptor); _instance ._show( From 098ec84a4e0be21515245d0b9d89bb2148d23120 Mon Sep 17 00:00:00 2001 From: Fedor Blagodyr Date: Sat, 13 Aug 2022 16:54:26 +0300 Subject: [PATCH 4/6] fix(back-button): Updated bool logic --- lib/src/easy_loading.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index 76b6598..6c3350c 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -261,7 +261,7 @@ class EasyLoading { w: w, ); - final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); + final isIgnoringBackButton = !(_instance.userInteractions ?? false); if (!isIgnoringBackButton) return showFunc(); @@ -300,7 +300,7 @@ class EasyLoading { value: value, ); - final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); + final isIgnoringBackButton = !(_instance.userInteractions ?? false); if (isIgnoringBackButton) BackButtonInterceptor.add(_backButtonInterceptor); From 3e62700294aea7088b32fcdecb10f9a1c1766fe7 Mon Sep 17 00:00:00 2001 From: Fedor Blagodyr Date: Sat, 13 Aug 2022 17:07:32 +0300 Subject: [PATCH 5/6] Revert "fix(back-button): Updated bool logic" This reverts commit 098ec84a4e0be21515245d0b9d89bb2148d23120. --- lib/src/easy_loading.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index 6c3350c..76b6598 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -261,7 +261,7 @@ class EasyLoading { w: w, ); - final isIgnoringBackButton = !(_instance.userInteractions ?? false); + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); if (!isIgnoringBackButton) return showFunc(); @@ -300,7 +300,7 @@ class EasyLoading { value: value, ); - final isIgnoringBackButton = !(_instance.userInteractions ?? false); + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); if (isIgnoringBackButton) BackButtonInterceptor.add(_backButtonInterceptor); From 1d58b20385c607cfba83345910719dea5bfccf16 Mon Sep 17 00:00:00 2001 From: Fedor Blagodyr Date: Sat, 13 Aug 2022 17:26:17 +0300 Subject: [PATCH 6/6] feat(back-button): Some improvements Reorgonized adding interceptor --- lib/src/easy_loading.dart | 52 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index 76b6598..89ac53c 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -254,23 +254,19 @@ class EasyLoading { bool? dismissOnTap, }) { Widget w = indicator ?? (_instance.indicatorWidget ?? LoadingIndicator()); - showFunc() => _instance._show( - status: status, - maskType: maskType, - dismissOnTap: dismissOnTap, - w: w, - ); final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); - if (!isIgnoringBackButton) return showFunc(); - - BackButtonInterceptor.add(_backButtonInterceptor); + if (isIgnoringBackButton) { + BackButtonInterceptor.add(_backButtonInterceptor); + } - return (dismissOnTap ?? false) - ? showFunc().whenComplete( - () => BackButtonInterceptor.remove(_backButtonInterceptor)) - : showFunc(); + return _instance._show( + status: status, + maskType: maskType, + dismissOnTap: dismissOnTap, + w: w, + ); } /// show progress with [value] [status] [maskType], value should be 0.0 ~ 1.0. @@ -299,22 +295,18 @@ class EasyLoading { key: _progressKey, value: value, ); - final isIgnoringBackButton = !EasyLoadingTheme.ignoring(maskType); - if (isIgnoringBackButton) + if (isIgnoringBackButton) { BackButtonInterceptor.add(_backButtonInterceptor); + } - _instance - ._show( - status: status, - maskType: maskType, - dismissOnTap: false, - w: w, - ) - .whenComplete( - () => BackButtonInterceptor.remove(_backButtonInterceptor), - ); + _instance._show( + status: status, + maskType: maskType, + dismissOnTap: false, + w: w, + ); _instance._progressKey = _progressKey; } // update progress @@ -413,8 +405,14 @@ class EasyLoading { // cancel timer _instance._cancelTimer(); return _instance._dismiss(animation).whenComplete( - () => BackButtonInterceptor.remove(_backButtonInterceptor), - ); + () { + final isIgnoringBackButton = !EasyLoadingTheme.ignoring(null); + + if (!isIgnoringBackButton) return; + + BackButtonInterceptor.remove(_backButtonInterceptor); + }, + ); } /// add loading status callback