diff --git a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart index 8be249d7..35eddf07 100644 --- a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart +++ b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart @@ -1400,14 +1400,16 @@ class ReownAppKitModal @override void closeModal({bool disconnectSession = false}) async { + // If we aren't open, then we can't and shouldn't close. + // This is a necessary check to avoid unnecessary navigator pops. + if (!_isOpen) { + return; + } + _disconnectOnClose = disconnectSession; - // If we aren't open, then we can't and shouldn't close _close(); if (_context != null) { - final canPop = Navigator.of(_context!, rootNavigator: true).canPop(); - if (canPop) { - Navigator.of(_context!, rootNavigator: true).pop(); - } + Navigator.maybeOf(_context!, rootNavigator: true)?.maybePop(); } _notify(); }