title: returning null user back from function
body: <p>I am working on Login page with Local db SQL in flutter.</p>
  
  <p>The page isn't creating a SQL table and returning null user, thus showing the snackbar "wrong email".</p>
  
  <p>I have tried to debug but can't find the solution as i am pretty new at this.<br>
  This is my sign up page:</p>
  
  <pre><code>   class _RegisterState extends State&lt;Register&gt; {
  
     DatabaseHelper db = new DatabaseHelper();
  
  TextEditingController emailController = TextEditingController();
  TextEditingController mobileController = TextEditingController();
  
  Future&lt;User&gt; _loginUser(String email,String mobile) async{
    User saveUser = User.fromMapObject({
      email:"hfah@gmail.com",
      mobile:"1432567890"
  
    });
    await db.saveUser(saveUser).then((val) async {
      if(val == 1){
        User user = await db.loginUser(email, mobile);
        return user;
      }
    });
  }
  
  
  final _formKey = GlobalKey&lt;FormState&gt;();
  final scaffoldKey = new GlobalKey&lt;ScaffoldState&gt;();
  
  @override
  Widget build(BuildContext context) {
    final bgColor = const Color(0xFF4b0081);
  
  return Scaffold(
    resizeToAvoidBottomPadding: false,
    backgroundColor: bgColor,
    key: scaffoldKey,
    body: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: &lt;Widget&gt;[
        Image(
          image: AssetImage("assets/newlogo2.png"),
          width: 200,
          height: 50,
        ),
  
        Container(
          padding: const EdgeInsets.only(top:20.0, right: 20, left: 20),
          child: Form(
            key: _formKey,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: &lt;Widget&gt;[
                TextFormField(
                  decoration: InputDecoration(
                      labelText: "Mobile No",
                      labelStyle: TextStyle(color: Colors.white)
                  ),
                  style: TextStyle(color: Colors.white, fontSize: 20.0),
                  onChanged: (val) {
                    setState(() =&gt; mob = val);
                  },
                  controller: emailController,
                ),
                SizedBox(height: 20.0,),
                TextFormField(
                  validator: (val) =&gt; val.isEmpty ? 'Enter an Email' : null,
                  decoration: InputDecoration(
                      labelText: "Email ID",
                      labelStyle: TextStyle(color: Colors.white)
                  ),
                  style: TextStyle(color: Colors.white, fontSize: 20.0),
                  onChanged: (val){
                    setState(() =&gt; email = val);
                  },
                  controller: mobileController,
  
                ),
                SizedBox(height: 20.0,),
                RaisedButton(
                  color: Colors.white,
                  child: Text(
                    'Register',
                    style: TextStyle(color: bgColor),
                  ),
                  onPressed: () async {
                   User user = await _loginUser(emailController.text, mobileController.text);
                    if(user != null){
                      Navigator.of(context).push(MaterialPageRoute&lt;Null&gt;(
                          builder: (BuildContext context){
                            return new Home(
                              user:user,
                            );
                          }
                      ));
                    }else{
                      scaffoldKey.currentState.showSnackBar(
                          SnackBar(content: Text("Wrong email"),)
                        );
  
                    }
                  },
                  splashColor: Colors.grey,
                ),
                SizedBox(height: 12.0,),
                Text(
                  error,
                  style: TextStyle(
                      color: Colors.red,
                      fontSize: 14.0
                  ),
                ),
                FlatButton(
                  color: bgColor,
                  child: Text(
                    'Back to Sign In',
                    style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
                  ),
                  onPressed: () async {
                    setState(() {
                      //widget.toggleView();
                    },);
                  },
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  
  );
  }
  </code></pre>
  
  <p>This is DatabaseHelper class</p>
  
  <pre><code>class DatabaseHelper{
     static final DatabaseHelper _instance = new DatabaseHelper.internal();
     factory DatabaseHelper() =&gt; _instance;
  
    static Database _db;
  
    String colemail = 'emial_id';
    String tablename = 'User';
     String colMobile = 'mobild_no';
  
  
    Future&lt;Database&gt; get db async{
      if(_db != null) return _db;
      _db = await initDb();
      return _db;
     }
  
     DatabaseHelper.internal();
  
     initDb() async{
       io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
       String path = join(documentsDirectory.path, "main.db");
       var theDb = await openDatabase(path,version:1,onCreate: _onCreate);
      return theDb;
     }
  
  
    void _onCreate(Database db,int version) async{
      await db.execute("""
       CREATE TABLE User(
          user_id INTEGER PRIMARY KEY,
          email_id TEXT,
          mobile_no TEXT
         )""");
      print("Table created");
     }
  
    Future&lt;int&gt; saveUser(User user) async{
        var dbClient = await db;
        int res = await dbClient.insert(tablename, user.toMap());
        return res;
    }
  
  
  
    Future&lt;User&gt; loginUser(String email,String mobile) async{
        var dbClient = await db;
        String sql = "SELECT * FROM User WHERE email_id = '$email' AND 
           mobile_no = '$mobile' ";
        var result = await dbClient.rawQuery(sql);
        if(result.length == 0) return null;
  
         return User.fromMapObject(result.first);
     }
  }
  </code></pre>
  
  <p>And this is User class</p>
  
  <pre><code>class User{
      int _user_id;
      String email_id;
      String mobile_no;
  
     User(this.email_id,this.mobile_no,this._user_id);
  
     String get emailID =&gt; email_id;
     String get mobileNO =&gt; mobile_no;
     int get user_id =&gt;_user_id;
  
   set emailID(String newMail){
       this.email_id = newMail;
     }
  
   set mobileNO(String newMob){
      this.mobile_no = newMob;
   }
  
   Map &lt;String,dynamic&gt; toMap(){
     return {
       'email_id': email_id,
       'mobile_no': mobile_no,
       'user_id':_user_id
     };
   }
  
   User.fromMapObject(dynamic map){
       this.email_id = map['email_id'];
       this.mobile_no = map['mobile_no'];
       this._user_id = map['user_id'];
   }
  }
  </code></pre>
  
  <p>Please help !!!</p>