back_button_interceptor_plus 8.1.1
back_button_interceptor_plus: ^8.1.1 copied to clipboard
Flutter 升级 3.35.7 之后,对 back_button_interceptor 插件的升级(After Flutter upgrade 3.35.7, the upgrade of back_button_interceptor plugins.)。
// Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg
// For more info, see: https://pub.flutter-io.cn/packages/back_button_interceptor_plus
import 'package:back_button_interceptor_plus/back_button_interceptor_plus.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.'),
),
),
);
}
}