modal_will_scope.dart
1.4 KB
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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ModalWillScope extends StatelessWidget {
final ScrollController scrollController;
const ModalWillScope({Key key, this.scrollController}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(child: WillPopScope(
onWillPop: () async {
bool shouldClose = true;
await showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Should Close?'),
actions: <Widget>[
CupertinoButton(
child: Text('Yes'),
onPressed: () {
shouldClose = true;
Navigator.of(context).pop();
},
),
CupertinoButton(
child: Text('No'),
onPressed: () {
shouldClose = false;
Navigator.of(context).pop();
},
),
],
));
print('hello');
return shouldClose;
},
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
leading: Container(), middle: Text('Modal Page')),
child: Center(),
),
));
}
}