back_button_interceptor 2.0.1 copy "back_button_interceptor: ^2.0.1" to clipboard
back_button_interceptor: ^2.0.1 copied to clipboard

outdated

Back Button Interceptor. May be used to intercept the Android back-button, as an alternative to `WillPopScope`.

back_button_interceptor #

When you need to intercept the Android back-button, you usually add WillPopScope to your widget tree. However, under some use cases, specially when developing stateful widgets that interact with the back button, it may be more convenient to use the BackButtonInterceptor.

You may add functions to be called when the back button is tapped. These functions may perform some useful work, and then, if any of them return true, the default button process (usually popping a Route) will not be fired.

In more detail: All added functions are called, in order. If any function returns true, the combinedResult is true, and the default button process will NOT be fired. Only if all functions return false (or null), the combinedResult is false, and the default button process will be fired. Each function gets a boolean that indicates the current combinedResult from all the previous functions.

Note: After you've finished you MUST remove each function by calling the remove() method.

Usage #

Import the package #

First, add back_button_interceptor as a dependency in your pubspec.yaml

Then, import it:

import 'package:back_button_interceptor/back_button_interceptor.dart';

Example usage #

@override
void initState() {
   super.initState();
   BackButtonInterceptor.add(myInterceptor);
}

@override
void dispose() {
   BackButtonInterceptor.remove(myInterceptor);
   super.dispose();
}

bool myInterceptor(bool stopDefaultButtonEvent) {
   print("BACK BUTTON!"); // Do some stuff.
   return true;
}

Don't forget to check the example tab.

See also:

306
likes
0
pub points
98%
popularity

Publisher

verified publisherglasberg.dev

Back Button Interceptor. May be used to intercept the Android back-button, as an alternative to `WillPopScope`.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on back_button_interceptor