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

How can disable Android back button when show loading? #203

Open
yendangn opened this issue Feb 17, 2023 · 8 comments
Open

How can disable Android back button when show loading? #203

yendangn opened this issue Feb 17, 2023 · 8 comments

Comments

@yendangn
Copy link

Describe the bug
When show loading, app can back to previous screen by tap on back hardware button on Android.
Flutter/Dart info

`Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.9, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✗] Cannot determine if IntelliJ is installed
✗ Directory listing failed
[✓] VS Code (version 1.73.1)
[✓] Connected device (5 available)
! Error: YenDang is busy: Fetching debug symbols for YenDang. Xcode will continue when YenDang is finished. (code -10)
! Error: Dang’s Apple Watch needs to connect to determine its availability. Check the connection between the device and its companion iPhone, and the connection between the iPhone and Xcode. Both devices may also need to be restarted and unlocked. (code 1)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.
`

@github-actions
Copy link

Thanks for taking the time to open an issue. I will have a look and answer as soon as possible.

@SajidGohar
Copy link

Any solution for this...?

@ProZhar
Copy link

ProZhar commented Sep 19, 2023

Same problem.

@zmeid
Copy link

zmeid commented Sep 26, 2023

any updates?

EasyLoading.instance.userInteractions = false doesn't prevent back button taps.

@norman93sun
Copy link

Any solution ?

@FadyFayezYounan
Copy link

FadyFayezYounan commented Jun 4, 2024

Hello my friends you can make this solution:

just wrap your scaffold with this widget and it will disable the back button

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class OverlayLoadingPopScope extends StatefulWidget {
  const OverlayLoadingPopScope({super.key, required this.child});
  final Widget child;

  @override
  State<OverlayLoadingPopScope> createState() => _OverlayLoadingPopScopeState();
}

class _OverlayLoadingPopScopeState extends State<OverlayLoadingPopScope> {
  late final ValueNotifier<bool> _loadingNotifier;

  @override
  void initState() {
    super.initState();
    _loadingNotifier = ValueNotifier<bool>(false);
    EasyLoading.addStatusCallback(_statusCallback);
  }

  @override
  void dispose() {
    _loadingNotifier.dispose();
    EasyLoading.removeCallback(_statusCallback);
    super.dispose();
  }

  void _statusCallback(EasyLoadingStatus status) {
    if (status == EasyLoadingStatus.show) {
      _loadingNotifier.value = true;
    } else {
      _loadingNotifier.value = false;
    }
  }

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<bool>(
      valueListenable: _loadingNotifier,
      builder: (context, isLoading, child) => PopScope(
        canPop: isLoading == false,
        child: child!,
      ),
      child: widget.child,
    );
  }
}

@AhmedPothiyawala
Copy link

Anyone please response to him

@AhmedPothiyawala
Copy link

any updates?

EasyLoading.instance.userInteractions = false doesn't prevent back button taps.

Not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants