fix initial load bug
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class Globals {
|
||||
static final Globals _singleton = Globals._internal();
|
||||
@@ -18,6 +19,8 @@ class Globals {
|
||||
String platform = '';
|
||||
String hostname = '';
|
||||
|
||||
late SharedPreferences sharedPrefs;
|
||||
|
||||
Future<void> init() async {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
|
||||
@@ -27,5 +30,7 @@ class Globals {
|
||||
this.buildNumber = packageInfo.buildNumber;
|
||||
this.platform = Platform.operatingSystem;
|
||||
this.hostname = Platform.localHostname;
|
||||
|
||||
this.sharedPrefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/models/key_token_auth.dart';
|
||||
import 'package:simplecloudnotifier/models/user.dart';
|
||||
import 'package:simplecloudnotifier/state/globals.dart';
|
||||
|
||||
class UserAccount extends ChangeNotifier {
|
||||
User? _user;
|
||||
@@ -37,11 +38,9 @@ class UserAccount extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void load() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
final uid = prefs.getString('auth.userid');
|
||||
final tok = prefs.getString('auth.token');
|
||||
void load() {
|
||||
final uid = Globals().sharedPrefs.getString('auth.userid');
|
||||
final tok = Globals().sharedPrefs.getString('auth.token');
|
||||
|
||||
if (uid != null && tok != null) {
|
||||
setToken(KeyTokenAuth(userId: uid, token: tok));
|
||||
|
Reference in New Issue
Block a user