feat: skip login screen when logged in (#191)

This commit is contained in:
Shreyas Thirumalai 2021-02-05 09:11:55 +05:30 committed by GitHub
parent a1021465a8
commit 3b88ad01f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -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<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)) ??

View File

@ -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';