nslogx / flutter_easyloading

✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web
https://pub.dev/packages/flutter_easyloading
MIT License
1.24k stars 218 forks source link

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

Open yendangn opened 1 year ago

yendangn commented 1 year ago

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[bot] commented 1 year ago

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

SajidGohar commented 1 year ago

Any solution for this...?

ProZhar commented 12 months ago

Same problem.

zmeid commented 11 months ago

any updates?

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

norman93sun commented 4 months ago

Any solution ?

FadyFayezYounan commented 3 months ago

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 commented 2 months ago

Anyone please response to him

AhmedPothiyawala commented 2 months ago

any updates?

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

Not working