title: flutter: check if user logged in
body: <p>i've implemented android application using flutter , and i have created a login/signup form , it works perfect when connected with API but the problem is after i logged in and go back to any other page again when i click on the login button it shows me again the login form , what i want is to add function that detects if user logged in or not , is there a way to do it?
  ps:  i tried sharedPrefrences below but it doesn't work</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>main() async {
    // if your flutter &gt; 1.7.8 :  ensure flutter activated
    WidgetsFlutterBinding.ensureInitialized();
      final SharedPreferences prefs = await SharedPreferences.getInstance();
    var isLoggedIn = prefs.getBool('isLoggedIn')??false;
  
    await translator.init(
      localeDefault: LocalizationDefaultType.device,
      languagesList:   &lt;String&gt;['en', 'ar'],
      assetsDirectory: 'assets/langs/',
      apiKeyGoogle: '&lt;Key&gt;', // NOT YET TESTED
    );
  
    // WidgetsFlutterBinding.ensureInitialized();
  
    runApp(
      LocalizedApp(
        child: Notification(isLoggedIn:isLoggedIn),
      ),
    );
  }
  
  
  class Notification extends StatefulWidget {
      final bool isLoggedIn;
    Notification({this.isLoggedIn});
  
    @override
    _NotificationState createState() =&gt; _NotificationState();
  }
  
  class _NotificationState extends State&lt;Notification&gt; {
    @override
    Widget build(BuildContext context) {
      return MultiProvider(
        providers: [
     Products_FitnessAndGym()),
          ChangeNotifierProvider.value(value: Cart()),
          ChangeNotifierProvider.value(value: Wishe()),
          ChangeNotifierProvider.value(
            value: Orders(),
          )
        ],
        
        child: MaterialApp(
          
            debugShowCheckedModeBanner: false,
            home: 
             widget.isLoggedIn ? MyHomePage(): LogIn(),
            localizationsDelegates:
                translator.delegates, /</code></pre>
  </div>
  </div>
  </p>
  <p>and this my main.dart:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>main() async {
    // if your flutter &gt; 1.7.8 :  ensure flutter activated
    WidgetsFlutterBinding.ensureInitialized();
  
    await translator.init(
      localeDefault: LocalizationDefaultType.device,
      languagesList: &lt;String&gt;['en', 'ar'],
      assetsDirectory: 'assets/langs/',
      apiKeyGoogle: '&lt;Key&gt;', // NOT YET TESTED
    );
  //   Future&lt;void&gt; main() async {
  //   WidgetsFlutterBinding.ensureInitialized();
  //   final SharedPreferences prefs = await SharedPreferences.getInstance();
  //   var isLoggedIn = (prefs.getBool('isLoggedIn') == null)
  //       ? false
  //       : prefs.getBool('isLoggedIn');
  //   // runApp(MaterialApp(
  //   //   debugShowCheckedModeBanner: false,
  //   //   home: isLoggedIn ? Home() : LogIn(),
  //   // ));
  // }
  
    runApp(
      LocalizedApp(
        child: Notification(),
      ),
    );
  }
  
  
  class Notification extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MultiProvider(
        providers: [
          
     
          ChangeNotifierProvider.value(value: Products_FitnessAndGym()),
          ChangeNotifierProvider.value(value: Cart()),
          ChangeNotifierProvider.value(value: Wishe()),
          ChangeNotifierProvider.value(
            value: Orders(),
          )
        ],
        
        child: MaterialApp(
          
            debugShowCheckedModeBanner: false,
            home: 
             isLoggedIn ? MyHomePage(): LogIn(),
            localizationsDelegates:
                translator.delegates, // Android + iOS Delegates
            locale: translator.locale, // Active locale
            supportedLocales: translator.locals(),
            .........
            ........</code></pre>
  </div>
  </div>
  </p>