title: Access other Class method in Flutter/dart
body: <p>I was working on login with preference. Everything is working fine when I wrote all code in main.dart. </p>
  
  <p>Problem: </p>
  
  <p>When I create separate class on MySharePref then I am getting some error. </p>
  
  <p>MySharePref.dart</p>
  
  <pre><code>import 'package:first_app/UserModel.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  
  class SharePrefClass {
  
  
    void _saveData(UserModel model) async{
  
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setString("Username",model.userName);
      await prefs.setString("Password", model.password);
    }
    Future&lt;UserModel&gt; _getData() async{
      SharedPreferences preferences = await SharedPreferences.getInstance();
      String username =  preferences.getString("Username");
      String password = preferences.getString("Password");
      UserModel model = UserModel(username,password);
      return model;
    }
  
  }
  </code></pre>
  
  <p>I want to access these both functions in main.dart:</p>
  
  <pre><code>_checkLogin() async {
       UserModel userModel = new UserModel(
        userNameEditText.text , passwordEditText.text); 
  
     SharePrefClass mySharedPref = new SharePrefClass();
     final UserModel returnModel = mySharedPref._getData() ;
  
      if(returnModel.userName == ""){
        print("No data");
      }else{
        print("else executed");
      }
    }
  </code></pre>
  
  <p>I am getting error:</p>
  
  <p><a href="https://i.stack.imgur.com/iYXHJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iYXHJ.png" alt="enter image description here"></a></p>