flutter_easyloading icon indicating copy to clipboard operation
flutter_easyloading copied to clipboard

How can disable Android back button when show loading?

Open yendangn opened this issue 2 years ago • 8 comments

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. `

yendangn avatar Feb 17 '23 09:02 yendangn

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

github-actions[bot] avatar Feb 17 '23 09:02 github-actions[bot]

Any solution for this...?

SajidGohar avatar Jun 01 '23 12:06 SajidGohar

Same problem.

ProZhar avatar Sep 19 '23 14:09 ProZhar

any updates?

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

zmeid avatar Sep 26 '23 21:09 zmeid

Any solution ?

norman93sun avatar May 10 '24 07:05 norman93sun

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,
    );
  }
}

FadyFayezYounan avatar Jun 04 '24 16:06 FadyFayezYounan

Anyone please response to him

AhmedPothiyawala avatar Jul 04 '24 07:07 AhmedPothiyawala

any updates?

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

Not working

AhmedPothiyawala avatar Jul 04 '24 07:07 AhmedPothiyawala