1

I am facing an error while trying to create a user with an email and password. It is giving an error with the value null.

body: Container(
  child: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      TextField(
        decoration: InputDecoration(labelText: "Email"),
        onChanged: (value) {
          setState(() {
            _email = value;
          });
        },
      ),
      TextField(
        decoration: InputDecoration(labelText: "Password"),
        onChanged: (value) {
          setState(() {
            _password = value;
          });
        },
        obscureText: true,
      ),
      FlatButton(
          onPressed: () async {
            try {
              final newuser = await _auth.createUserWithEmailAndPassword(
                  _email, _password); // this is the line for the error
            

              if (newuser != Null) {
                Navigator.pushNamed(context, '/homepage');
              }
            } catch (e) {
              print(e);
            }
          },
          child: Text("Sign Up"))
    ],
  ),
));

if some one can help me with this it will be helpful

karel
  • 5,489
  • 46
  • 45
  • 50
Ravi Kumar
  • 11
  • 1

1 Answers1

0

By the looks of the error, you are passing _email and _password as null to the function. Tried using the ?? in case you have a null variable. For example Your_Function(_email ?? "", _password ?? "")

The ?? operator basically means, If the variable is null, use this value. So, if _email is null, use "". For more info, I suggest checking this answer.

IcyHerrscher
  • 391
  • 3
  • 9