Fix bug where accounts would be removed while being iterated over

This commit is contained in:
shilangyu 2021-01-17 17:35:07 +00:00
parent f37da51137
commit e2af8326e2
1 changed files with 12 additions and 9 deletions

View File

@ -69,7 +69,8 @@ class AccountsStore extends ChangeNotifier {
/// automatically sets default accounts
void _assignDefaultAccounts() {
// remove dangling defaults
_defaultAccounts.entries.map((dft) {
_defaultAccounts.entries
.map((dft) {
final instance = dft.key;
final username = dft.value;
// if instance or username doesn't exist, remove
@ -77,7 +78,9 @@ class AccountsStore extends ChangeNotifier {
!usernamesFor(instance).contains(username)) {
return instance;
}
}).forEach(_defaultAccounts.remove);
})
.toList()
.forEach(_defaultAccounts.remove);
if (_defaultAccount != null) {
final instance = _defaultAccount.split('@')[1];
final username = _defaultAccount.split('@')[0];