-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.dart
49 lines (42 loc) · 1.28 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg
// For more info, see: https://pub.dartlang.org/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.'),
),
),
);
}
}