From 7ededd739dad97b43ffed2459f18aa4dd5a4a2de Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 4 Jun 2023 10:03:00 +0200 Subject: [PATCH] neon: Fix missing active account --- .../neon/neon/lib/src/blocs/accounts.dart | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 4d79f044..c1d8a16e 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -37,19 +37,29 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState }); final as = accounts.value; + if (_globalOptions.rememberLastUsedAccount.value && _storage.containsKey(_keyLastUsedAccount)) { final lastUsedAccountID = _storage.getString(_keyLastUsedAccount); - activeAccount.add(lastUsedAccountID != null ? as.find(lastUsedAccountID) : null); - } else { - unawaited( - _globalOptions.initialAccount.stream.first.then((final lastAccount) { - final account = lastAccount != null ? as.find(lastAccount) : null; + if (lastUsedAccountID != null) { + final aa = as.find(lastUsedAccountID); + if (aa != null) { + setActiveAccount(aa); + } + } + } + + unawaited( + _globalOptions.initialAccount.stream.first.then((final lastAccount) { + final account = lastAccount != null ? as.find(lastAccount) : null; + if (activeAccount.valueOrNull == null) { if (account != null) { - activeAccount.add(account); + setActiveAccount(account); + } else if (as.isNotEmpty) { + setActiveAccount(as.first); } - }), - ); - } + } + }), + ); } final RequestManager _requestManager;