flutter_easyloading icon indicating copy to clipboard operation
flutter_easyloading copied to clipboard

Add backbutton interceptor support.

Open indiegoxx opened this issue 4 years ago • 2 comments

following plugin backbuttonintercept could be integrated wherein a disable back button flag could be added to disable the android back button when the loader is showing.

indiegoxx avatar Jul 14 '21 17:07 indiegoxx

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

github-actions[bot] avatar Jul 14 '21 17:07 github-actions[bot]

A simple way to get around this issue is to create a wrapper class around EasyLoader and implement the BackButtonInterceptor plugin inside it like so :

import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class Loader {
  static void show({String? status}) {
    // Intercept the back button
    BackButtonInterceptor.add(interceptor);

    // Show the loader
    EasyLoading.show(
      status: status
    );
  }

  static void dismiss() {
    // Dismiss the loader
    EasyLoading.dismiss();

    // Dismiss the back button interceptor
    BackButtonInterceptor.remove(interceptor);
  }

  // Back button interceptor function
  static bool interceptor(bool stopEvent, RouteInfo info) {
    // Do whatever you want when intercepting the back button
    return true;
  }
}

Then you can call the loader anywhere in your code like so :

// ...
import 'package:your_app/wrapper/path/loader.dart';

// ...

Loader.show(
  status: 'The loader status message'
);

// Do some stuff while the loader is displayed

Loader.dismiss();

// ...

I'm not sure it's the best way to do it, but it should cover simple use cases.

Tof-Arei avatar Jun 20 '22 07:06 Tof-Arei