diff --git a/lib/models/auth.dart b/lib/models/auth.dart index 4bd751f3..a8c2fd70 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -631,6 +631,12 @@ class AuthModel with ChangeNotifier { _accounts = (json.decode(str ?? '[]') as List) .map((item) => Account.fromJson(item)) .toList(); + activeAccountIndex = prefs.getInt(StorageKeys.defaultAccount); + + if (activeAccount != null) + _activeTab = prefs.getInt( + StorageKeys.getDefaultStartTabKey(activeAccount.platform)) ?? + 0; } catch (err) { Fimber.e('prefs getAccount failed', ex: err); _accounts = []; @@ -645,11 +651,19 @@ class AuthModel with ChangeNotifier { super.dispose(); } + Future setDefaultAccount(int v) async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setInt(StorageKeys.defaultAccount, v); + Fimber.d('write default account: $v'); + notifyListeners(); + } + var rootKey = UniqueKey(); setActiveAccountAndReload(int index) async { // https://stackoverflow.com/a/50116077 rootKey = UniqueKey(); activeAccountIndex = index; + setDefaultAccount(activeAccountIndex); final prefs = await SharedPreferences.getInstance(); _activeTab = prefs.getInt( StorageKeys.getDefaultStartTabKey(activeAccount.platform)) ?? diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 38b20cdb..4f69e776 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -27,6 +27,7 @@ class StorageKeys { static const iCodeFontSize = 'code-font-size'; static const codeFontFamily = 'code-font-family'; static const markdown = 'markdown'; + static const defaultAccount = 'default-account'; static getDefaultStartTabKey(String platform) => 'default-start-tab-$platform';