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

Back Button Interceptor. May be used to do stuff when the Android back-button is tapped, as an alternative to `WillPopScope`.

example/lib/main.dart

// Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg
// For more info, see: https://pub-web.flutter-io.cn/packages/back_button_interceptor
import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter/material.dart';

// When pressing the back-button, a message will be printed to the console,
// and no back action will happen.

void main() => runApp(MaterialApp(home: Demo()));

class Demo extends StatefulWidget {
  @override
  DemoState createState() => DemoState();
}

class DemoState extends State<Demo> {
  //
  @override
  void initState() {
    super.initState();
    BackButtonInterceptor.add(myInterceptor);
  }

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

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

  @override
  Widget build(BuildContext context) {
    //
    return Scaffold(
      appBar: AppBar(title: const Text('Back Button Interceptor Example')),
      body: Container(
        color: Colors.green,
        child: const Center(
          child: Text('Click the Back Button\n'
              'and see the message in the console.'),
        ),
      ),
    );
  }
}
321
likes
150
pub points
98%
popularity

Publisher

verified publisherglasberg.dev

Back Button Interceptor. May be used to do stuff when the Android back-button is tapped, as an alternative to `WillPopScope`.

Repository (GitHub)
View/report issues

Topics

#button #android #navigation

Documentation

API reference

License

BSD-2-Clause (LICENSE)

Dependencies

collection, flutter

More

Packages that depend on back_button_interceptor