From 4f14690e05c188875a323afc1cab4be2904a6b94 Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Wed, 23 Oct 2024 17:17:45 +0200 Subject: [PATCH] Fix popScopesTill --- lib/get_it_impl.dart | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/get_it_impl.dart b/lib/get_it_impl.dart index a19b830..d63d48d 100644 --- a/lib/get_it_impl.dart +++ b/lib/get_it_impl.dart @@ -1474,18 +1474,21 @@ class _GetItImplementation implements GetIt { } String? poppedScopeName; _Scope nextScopeToPop = _currentScope; - do { + bool somethingWasPopped = false; + + while (nextScopeToPop.name != _baseScopeName && + hasScope(scopeName) && + (nextScopeToPop.name != scopeName || inclusive)) { poppedScopeName = nextScopeToPop.name; await dropScope(poppedScopeName!); + somethingWasPopped = true; nextScopeToPop = _scopes.lastWhere((x) => x.isPopping == false); - if (nextScopeToPop.name == _baseScopeName) { - return true; - } - } while (hasScope(scopeName) && inclusive - ? (poppedScopeName != scopeName) - : (nextScopeToPop.name != scopeName)); - onScopeChanged?.call(false); - return true; + } + + if (somethingWasPopped) { + onScopeChanged?.call(false); + } + return somethingWasPopped; } /// Disposes all registered factories and singletons in the provided scope