title: How to decide default navigation in main.dart file and how to change it based on condition checking?
body: <p>I am trying to achieve user login session. I am willing to skip login screen and willing to navigate to the main screen. I have created two screens and implemented shared preferences to store user response. I am able to save and print it back. I am having an issue in if condition, where am trying to check a boolean value returning from a user-checking function which checks for saved shared preference value and return true or false based on that.</p>
  
  <pre><code>
  
      {
         return new MaterialApp(
            home: new Scaffold(
              body: ((checkUserAndNavigate(context))== true)
                  ? new HomeScreen()
                  : new LoginScreen(),
            ),
      }
  
  
      //Check if user login is saved
      Future checkUserAndNavigate(BuildContext context) async 
      {
        bool status;
        print("Checking user state");
        SharedPreferences preferences = await SharedPreferences.getInstance();
        String userdata = preferences.getString("userData");
        if (userdata != null) {
          status = true;
        } else {
          status = false;
        }
        return status;
      }
  
  </code></pre>
  
  <p>I am using ternary condition for checking and loading proper screen. but its the function in above code (checkUserAndNavigate(context))== true) is always saying some error like below
  <strong>"Equality operator '==' invocation with reference of unrelated types"</strong></p>
  
  <p>The complete code is below</p>
  
  <pre><code>
  
      import 'dart:async';
  
      import 'package:flutter/material.dart';
  
      import './app/src/screens/loginscreen.dart';
      import './app/src/screens/homescreen.dart';
      import 'package:shared_preferences/shared_preferences.dart';
  
      void main() => runApp(new MTrackNotificationsMain());
  
      class MTrackNotificationsMain extends StatelessWidget {
        // This widget is the root of your application.
        @override
        Widget build(BuildContext context) {
          // This widget is the root of your application
          return new MaterialApp(
            home: new Scaffold(
              body: (checkUserAndNavigate(context) == true)
                  ? new HomeScreen()
                  : new LoginScreen(),
            ),
            theme: new ThemeData(
              primaryColor: Colors.teal.shade400,
              primaryColorDark: Colors.teal.shade800,
              primarySwatch: Colors.teal,
              accentColor: Colors.teal.shade300,
            ),
            //Routes attribute work as screen navigator
            routes: {
              "/LoginScreen": (BuildContext context) => new LoginScreen(),
              '/HomeScreen': (BuildContext context) => new HomeScreen()
            },
          );
        }
      }
  
      //Check if user login is saved
      Future checkUserAndNavigate(BuildContext context) async {
        bool status;
        print("Checking user state");
        SharedPreferences preferences = await SharedPreferences.getInstance();
        String userdata = preferences.getString("userData");
        if (userdata != null) {
          status = true;
        } else {
          status = false;
        }
        return status;
      }
  
  </code></pre>