Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added back button interceptor #182

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) 提供支持

[<img src="https://raw.githubusercontent.com/nslogx/flutter_easyloading/master/images/jetbrains.png" width=200 height=112/>](https://www.jetbrains.com/?from=FlutterEasyLoading)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

[<img src="https://raw.githubusercontent.com/nslogx/flutter_easyloading/master/images/jetbrains.png" width=200 height=112/>](https://www.jetbrains.com/?from=FlutterEasyLoading)
Expand Down
30 changes: 29 additions & 1 deletion lib/src/easy_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -520,4 +542,10 @@ class EasyLoading {
_timer?.cancel();
_timer = null;
}

static bool _backButtonInterceptor(
bool stopDefaultButtonEvent,
RouteInfo routeInfo,
) =>
true;
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down