Skip to content

Commit

Permalink
feat: skip login screen when logged in (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas1599 committed Feb 5, 2021
1 parent a102146 commit 3b88ad0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/models/auth.dart
Expand Up @@ -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 = [];
Expand All @@ -645,11 +651,19 @@ class AuthModel with ChangeNotifier {
super.dispose();
}

Future<void> 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)) ??
Expand Down
1 change: 1 addition & 0 deletions lib/utils/utils.dart
Expand Up @@ -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';
Expand Down

0 comments on commit 3b88ad0

Please sign in to comment.