From cd2efdf6ca04103efbd99c138f88260c51763450 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 27 Jan 2026 22:42:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Check=20modal=20open=20state?= =?UTF-8?q?=20before=20calling=20navigator=20pop=20when=20closing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reown_appkit/lib/modal/appkit_modal_impl.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart index 8be249d7..dd098f06 100644 --- a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart +++ b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart @@ -1401,13 +1401,16 @@ class ReownAppKitModal @override void closeModal({bool disconnectSession = false}) async { _disconnectOnClose = disconnectSession; - // If we aren't open, then we can't and shouldn't close + + // 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; + } + _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(); } From a0f7f028ea183f61b6c9927631b68fb25bc0d0da Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 27 Jan 2026 23:44:22 +0800 Subject: [PATCH 2/2] Refactor closeModal to set disconnectOnClose after check --- packages/reown_appkit/lib/modal/appkit_modal_impl.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart index dd098f06..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,13 @@ class ReownAppKitModal @override void closeModal({bool disconnectSession = false}) async { - _disconnectOnClose = disconnectSession; - // 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; _close(); if (_context != null) { Navigator.maybeOf(_context!, rootNavigator: true)?.maybePop();