Advertisement
muhaiminurabir

exit pop up flutter

Jan 27th, 2025
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.15 KB | None | 0 0
  1.  @override
  2.   Widget build(BuildContext context) {
  3.     return PopScope(
  4.         canPop: false,
  5.         onPopInvokedWithResult: (didPop, result) {
  6.           if (didPop) {
  7.             return;
  8.           }
  9.           showExitPopup(context);
  10.         },
  11.         child: Scaffold(
  12.         )
  13.   }
  14.  
  15.  
  16.  Future<bool> showExitPopup(context) async {
  17.     return await showDialog(
  18.         context: context,
  19.         builder: (BuildContext context) {
  20.           return AlertDialog(
  21.             content: SizedBox(
  22.               height: 90,
  23.               child: Column(
  24.                 crossAxisAlignment: CrossAxisAlignment.start,
  25.                 children: [
  26.                   Text("Do you want to exit?"),
  27.                   SizedBox(height: 20),
  28.                   Row(
  29.                     children: [
  30.                       Expanded(
  31.                         child: ElevatedButton(
  32.                           onPressed: () {
  33.                             if (kDebugMode) {
  34.                               print('yes selected');
  35.                             }
  36.                             exit(0);
  37.                           },
  38.                           style: ElevatedButton.styleFrom(
  39.                               backgroundColor: ProjectColors.appbarColor),
  40.                           child: Text(
  41.                             "Yes",
  42.                             style: TextStyle(color: ProjectColors.white),
  43.                           ),
  44.                         ),
  45.                       ),
  46.                       SizedBox(width: 15),
  47.                       Expanded(
  48.                           child: ElevatedButton(
  49.                             onPressed: () {
  50.                               Navigator.of(context).pop();
  51.                             },
  52.                             style: ElevatedButton.styleFrom(
  53.                               backgroundColor: Colors.white,
  54.                             ),
  55.                             child:
  56.                             Text("No", style: TextStyle(color: Colors.black)),
  57.                           ))
  58.                     ],
  59.                   )
  60.                 ],
  61.               ),
  62.             ),
  63.           );
  64.         });
  65.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement