fix: 'No' button in unsaved-changes dialog does not navigate back#512
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the "No" button in the unsaved changes dialog on the Task Edit screen did not navigate back to the previous screen. The fix updates the dialog's return values and the onWillPop handler logic to properly distinguish between the three user actions: saving changes (Yes), discarding changes (No), and canceling the navigation (Cancel).
Key Changes
- Updated the "No" button to return
falsefrom the dialog instead ofvoid - Updated the "Cancel" button to return
nullinstead offalse - Modified the
onWillPophandler to allow navigation for bothtrue(save) andfalse(discard) cases, while blocking navigation only fornull(cancel)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (save == null) { | ||
| // Cancel → stay | ||
| return false; | ||
| } | ||
| // Yes (true) or No (false) → both allow popping the screen | ||
| return true; |
There was a problem hiding this comment.
[nitpick] Consider using an enum-based approach similar to taskc_details_controller.dart for better type safety and maintainability. That module defines UnsavedChangesAction { save, discard, cancel } and uses it in the dialog and handleWillPop method. This would make the intent clearer than using bool? values, especially since you now have three distinct actions (Yes/No/Cancel) rather than true/false/null.
Description
Fixes the behavior of the unsaved-changes dialog shown when leaving the Task Edit screen.
Previously the No button closed the dialog without returning a value, which caused the
onWillPophandler to treat it like a cancel and prevented navigation back. This change makes the No button returnfalsefrom the dialog and updatesonWillPopso that:Yes→ saves then allows the route to pop,No→ discards changes and allows the route to pop,Cancel→ stays on the page (no pop).Fixes #511
Screenshots
Before (issue):
(see issue #511 for the before video)
After (this PR):
after.mp4
Tapping "No" now discards changes and navigates back to the previous screen
Checklist