From e2f103a807291fd0cec12dcca641c70e66f3fa18 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Mon, 31 May 2021 00:03:53 +0800 Subject: [PATCH] fix: empty accounts --- lib/models/auth.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/models/auth.dart b/lib/models/auth.dart index e538ed6..8d1ce3e 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -65,15 +65,15 @@ class AuthModel with ChangeNotifier { // static final inAppReview = InAppReview.instance; var hasRequestedReview = false; - List? _accounts; + List _accounts = []; int? activeAccountIndex; late StreamSubscription _sub; bool loading = false; List? get accounts => _accounts; Account? get activeAccount { - if (activeAccountIndex == null || _accounts == null) return null; - return _accounts![activeAccountIndex!]; + if (activeAccountIndex == null || _accounts.isEmpty) return null; + return _accounts[activeAccountIndex!]; } String get token => activeAccount!.token; @@ -89,7 +89,7 @@ class AuthModel with ChangeNotifier { if (activeAccountIndex == index) { activeAccountIndex = null; } - _accounts!.removeAt(index); + _accounts.removeAt(index); // Save final prefs = await SharedPreferences.getInstance(); await prefs.setString(StorageKeys.accounts, json.encode(_accounts));