From 17f271dfb9f70f245127e2e63ff035c139a1db09 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 12 May 2020 19:04:53 +0200 Subject: [PATCH] Change the way we determine whether current user is signed in or not --- lib/helpers/account_helper.dart | 3 +++ lib/main.dart | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/helpers/account_helper.dart b/lib/helpers/account_helper.dart index f628385..e3b0c44 100644 --- a/lib/helpers/account_helper.dart +++ b/lib/helpers/account_helper.dart @@ -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!"; diff --git a/lib/main.dart b/lib/main.dart index 81cc7fb..8f09673 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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, ); }