mirror of
https://github.com/dancojocaru2000/logic-circuits-simulator.git
synced 2025-02-22 17:19:36 +02:00
Fixed cancelling new component
This commit is contained in:
parent
c8b5168413
commit
65e7d5f122
1 changed files with 31 additions and 26 deletions
|
@ -33,35 +33,40 @@ class EditComponentPage extends HookWidget {
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () async {
|
onWillPop: () async {
|
||||||
if (!dirty && !newComponent) {
|
if (!dirty && !newComponent) {
|
||||||
return true;
|
Navigator.of(context).pop(true);
|
||||||
} else if (!dirty && anySave.value) {
|
} else if (!dirty && anySave.value) {
|
||||||
return true;
|
Navigator.of(context).pop(true);
|
||||||
}
|
} else {
|
||||||
final dialogResult = await showDialog(
|
final dialogResult = await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop(true);
|
|
||||||
},
|
|
||||||
style: ButtonStyle(
|
|
||||||
backgroundColor: MaterialStateProperty.all(Colors.red),
|
|
||||||
),
|
),
|
||||||
child: const Text('Discard'),
|
ElevatedButton(
|
||||||
),
|
onPressed: () {
|
||||||
],
|
Navigator.of(context).pop(true);
|
||||||
title: Text('Cancel ${newComponent ? 'Creation' : 'Editing'}'),
|
},
|
||||||
content: Text(newComponent ? 'A new component will not be created.' : 'Are you sure you want to discard the changes?'),
|
style: ButtonStyle(
|
||||||
);
|
backgroundColor: MaterialStateProperty.all(Colors.red),
|
||||||
|
),
|
||||||
|
child: const Text('Discard'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
title: Text('Cancel ${newComponent ? 'Creation' : 'Editing'}'),
|
||||||
|
content: Text(newComponent ? 'A new component will not be created.' : 'Are you sure you want to discard the changes?'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (dialogResult == true) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
Navigator.of(context).pop(!newComponent);
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
return dialogResult == true;
|
return false;
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
|
Loading…
Add table
Reference in a new issue