🐛 Check modal open state before calling Navigator.pop when closing#332
🐛 Check modal open state before calling Navigator.pop when closing#332AlexV525 wants to merge 2 commits intoreown-com:developfrom
Navigator.pop when closing#332Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Navigator.pop() from being called when the AppKit modal was never opened, addressing issue #331.
Changes:
- Add an
_isOpenguard before attempting toNavigator.pop()incloseModal.
Comments suppressed due to low confidence (1)
packages/reown_appkit/lib/modal/appkit_modal_impl.dart:1411
closeModalcalls_close()before checking_isOpen. Since_close()sets_isOpen = falsewhen the modal was open, the new guardif (_isOpen && _context != null)will always be false in the open case, soNavigator.pop()will never run and the modal route may remain on the stack. Capture the previous open state (e.g.,final wasOpen = _isOpen;) before_close(), or move the pop logic into_close()before toggling_isOpenso you only pop when it was actually open.
// If we aren't open, then we can't and shouldn't close
_close();
if (_isOpen && _context != null) {
final canPop = Navigator.of(_context!, rootNavigator: true).canPop();
if (canPop) {
Navigator.of(_context!, rootNavigator: true).pop();
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ebc18dc to
b79103d
Compare
b79103d to
cd2efdf
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (canPop) { | ||
| Navigator.of(_context!, rootNavigator: true).pop(); | ||
| } | ||
| Navigator.maybeOf(_context!, rootNavigator: true)?.maybePop(); |
There was a problem hiding this comment.
hey @AlexV525 👋 do we need this change?
closeModal should close the modal unconditionally, and maybePop could refuse to close it in some cases, right?
There was a problem hiding this comment.
This is a regular practise navigation op for packages with my experience. Using maybePop will call predicate normally if users have customized the Navigator.
There was a problem hiding this comment.
Hey @AlexV525 sorry the delay 🙏
Agreed it’s good practice for general navigation, but _close() mutates internal state (sets _isOpen = false, clears widget stack) before the pop. If maybePop gets vetoed, the navigator and SDK state diverge — the modal is still on screen but the SDK considers it closed, and it won’t retry. Since this is our own programmatic dismiss, canPop() + pop() keeps things consistent.
Happy to keep just the !_isOpen guard — that’s the real fix.
Description
Adding
_isOpencheck when callingNavigator.popincloseModalto avoid unnecessary navigation changes.Resolves #331