mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Change the way we determine whether current user is signed in or not
This commit is contained in:
parent
c747d3c1ba
commit
17f271dfb9
@ -194,6 +194,9 @@ class AccountHelper {
|
|||||||
_currentUserID = preferences.getInt(_USER_ID_PREFERENCE_NAME);
|
_currentUserID = preferences.getInt(_USER_ID_PREFERENCE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if current user ID is loaded or not
|
||||||
|
static bool get isUserIDLoaded => _currentUserID > 0;
|
||||||
|
|
||||||
/// Get the ID of the currently signed in user
|
/// Get the ID of the currently signed in user
|
||||||
static int getCurrentUserID() {
|
static int getCurrentUserID() {
|
||||||
if (_currentUserID == -1) throw "Current user ID has not been loaded yet!";
|
if (_currentUserID == -1) throw "Current user ID has not been loaded yet!";
|
||||||
|
@ -21,31 +21,27 @@ void subMain() async {
|
|||||||
await initTranslations();
|
await initTranslations();
|
||||||
|
|
||||||
// Check if the user is currently signed in
|
// Check if the user is currently signed in
|
||||||
final signedIn = await AccountHelper().signedIn();
|
await AccountHelper().signedIn();
|
||||||
|
|
||||||
runApp(ComunicApplication(
|
runApp(ComunicApplication(
|
||||||
preferences: await PreferencesHelper.getInstance(),
|
preferences: await PreferencesHelper.getInstance(),
|
||||||
signedIn: signedIn,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComunicApplication extends StatelessWidget {
|
class ComunicApplication extends StatelessWidget {
|
||||||
final PreferencesHelper preferences;
|
final PreferencesHelper preferences;
|
||||||
final bool signedIn;
|
|
||||||
|
|
||||||
const ComunicApplication({
|
const ComunicApplication({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.preferences,
|
@required this.preferences,
|
||||||
@required this.signedIn,
|
|
||||||
}) : assert(preferences != null),
|
}) : assert(preferences != null),
|
||||||
assert(signedIn != null),
|
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: signedIn ? InitializeWidget() : LoginRoute(),
|
home: AccountHelper.isUserIDLoaded ? InitializeWidget() : LoginRoute(),
|
||||||
theme: preferences.preferences.enableDarkMode ? ThemeData.dark() : null,
|
theme: preferences.preferences.enableDarkMode ? ThemeData.dark() : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user