Forráskód Böngészése

Prompt to save edits

Vishnu Mohandas 4 éve
szülő
commit
1cde46fcc1
1 módosított fájl, 46 hozzáadás és 11 törlés
  1. 46 11
      lib/ui/image_editor_page.dart

+ 46 - 11
lib/ui/image_editor_page.dart

@@ -36,17 +36,23 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
 
   @override
   Widget build(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(
-        backgroundColor: Color(0x00000000),
-        elevation: 0,
-      ),
-      body: Container(
-        child: Column(
-          children: [
-            Expanded(child: _buildImage()),
-            _buildBottomBar(),
-          ],
+    return WillPopScope(
+      onWillPop: () async {
+        await _showExitConfirmationDialog();
+        return false;
+      },
+      child: Scaffold(
+        appBar: AppBar(
+          backgroundColor: Color(0x00000000),
+          elevation: 0,
+        ),
+        body: Container(
+          child: Column(
+            children: [
+              Expanded(child: _buildImage()),
+              _buildBottomBar(),
+            ],
+          ),
         ),
       ),
     );
@@ -325,4 +331,33 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
       max: 4,
     );
   }
+
+  Future<void> _showExitConfirmationDialog() async {
+    AlertDialog alert = AlertDialog(
+      title: Text("discard edits?"),
+      actions: [
+        TextButton(
+          child: Text("yes", style: TextStyle(color: Colors.red)),
+          onPressed: () {
+            Navigator.of(context, rootNavigator: true).pop('dialog');
+            Navigator.of(context).pop();
+          },
+        ),
+        TextButton(
+          child: Text("no", style: TextStyle(color: Colors.white)),
+          onPressed: () {
+            Navigator.of(context, rootNavigator: true).pop('dialog');
+          },
+        ),
+      ],
+    );
+
+    await showDialog(
+      context: context,
+      builder: (BuildContext context) {
+        return alert;
+      },
+      barrierColor: Colors.black87,
+    );
+  }
 }