Skip to content

Commit a68c301

Browse files
committed
container unsaved changes warning
1 parent 14489cb commit a68c301

2 files changed

Lines changed: 273 additions & 179 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024-2026 Fabian Freund.
3+
*
4+
* This file is part of WebLibre
5+
* (see https://weblibre.eu).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
import 'package:flutter/material.dart';
22+
23+
enum DiscardChangesChoice { discard, save }
24+
25+
Future<DiscardChangesChoice?> showDiscardChangesDialog(BuildContext context) {
26+
return showDialog<DiscardChangesChoice?>(
27+
context: context,
28+
builder: (BuildContext context) {
29+
return AlertDialog(
30+
icon: const Icon(Icons.warning),
31+
title: const Text('Unsaved Changes'),
32+
content: const Text(
33+
'You have unsaved changes. Do you want to save them before leaving?',
34+
),
35+
actions: <Widget>[
36+
TextButton(
37+
onPressed: () {
38+
Navigator.pop(context);
39+
},
40+
child: const Text('Cancel'),
41+
),
42+
TextButton(
43+
onPressed: () {
44+
Navigator.pop(context, DiscardChangesChoice.discard);
45+
},
46+
child: const Text('Discard'),
47+
),
48+
TextButton(
49+
onPressed: () {
50+
Navigator.pop(context, DiscardChangesChoice.save);
51+
},
52+
child: const Text('Save'),
53+
),
54+
],
55+
);
56+
},
57+
);
58+
}

0 commit comments

Comments
 (0)