1
0
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:
Pierre HUBERT 2020-05-12 19:04:53 +02:00
parent c747d3c1ba
commit 17f271dfb9
2 changed files with 5 additions and 6 deletions

View File

@ -194,6 +194,9 @@ class AccountHelper {
_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
static int getCurrentUserID() {
if (_currentUserID == -1) throw "Current user ID has not been loaded yet!";

View File

@ -21,31 +21,27 @@ void subMain() async {
await initTranslations();
// Check if the user is currently signed in
final signedIn = await AccountHelper().signedIn();
await AccountHelper().signedIn();
runApp(ComunicApplication(
preferences: await PreferencesHelper.getInstance(),
signedIn: signedIn,
));
}
class ComunicApplication extends StatelessWidget {
final PreferencesHelper preferences;
final bool signedIn;
const ComunicApplication({
Key key,
@required this.preferences,
@required this.signedIn,
}) : assert(preferences != null),
assert(signedIn != null),
super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: signedIn ? InitializeWidget() : LoginRoute(),
home: AccountHelper.isUserIDLoaded ? InitializeWidget() : LoginRoute(),
theme: preferences.preferences.enableDarkMode ? ThemeData.dark() : null,
);
}