Advertisement
Guest User

WillPopScope

a guest
Aug 12th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.82 KB | None | 0 0
  1. Widget build(BuildContext context) {
  2.     return WillPopScope(
  3.       onWillPop: _onExit,
  4.       child: Scaffold();
  5.  
  6. Future<bool> _onExit() async {
  7.     return showDialog(
  8.         context: context,
  9.         builder: (context) => AlertDialog(
  10.               title: Text("Exit"),
  11.               content: Text("Do you want to exit?"),
  12.               actions: <Widget>[
  13.                 RaisedButton(
  14.                   child: Text(
  15.                     "Nope",
  16.                   ),
  17.                   onPressed: () => Navigator.of(context).pop(),
  18.                 ),
  19.                 FlatButton(
  20.                     child: Text(
  21.                       "Yes",
  22.                       style: TextStyle(color: Colors.red[200]),
  23.                     ),
  24.                     onPressed: () => exit(0)),
  25.               ],
  26.             ));
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement