I'm following this https://medium.com/@c_innovative/simple-firebase-login-flow-in-flutter-6f44c2b5c58a tutorial and i am having some trouble with getting the login in to work. I have already connected my app to firebase and enabled email and password authentication on firebase console!

I have tried entering the key argument into the TextFormfield but so far im unable to do so.

class LoginPage extends StatefulWidget {
  State<StatefulWidget> createState() {
    return _LoginPageState();

class _LoginPageState extends State<LoginPage> {
  final _formKey = GlobalKey<FormState>();
  String _email;
  String _password;

  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Login Page Flutter Firebase"),
        body: Container(
          padding: EdgeInsets.all(20.0),
          child: Column(
            children: <Widget>[
              Spacer(flex: 5),
                "Login  Information",
                style: new TextStyle(fontSize: 30.0),
                flex: 5,
                key: _formKey,
                onSaved: (value) => _email = value,
                keyboardType: TextInputType.emailAddress,
                decoration: InputDecoration(labelText: "Email Address"),
                onSaved: (value) => _password = value,
                obscureText: true,
                decoration: InputDecoration(labelText: "Password"),
              Spacer(flex: 3),
                  child: Text("Login"),
                  onPressed: () async {
                    //Getting the error here
                    final form = _formKey.currentState;

                    if (form.validate()) {
                      print('$_email $_password');
                      var result = await 
                      Provider.of<AuthService(context).loginUser(email: _email, password:_password);
                      if (result == null) {
                        print("result is null");
                flex: 20,

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'save' was called on null. Receiver: null Tried calling: save()

this error message is what i get. somehow i understand that i have to initialise the receiver object(?) but i am confused on how to do so. Thanks for the help!

1 Answers

Adrian Murray On

Instead of using onSaved I'd just use TextEditingControllers on your fields and get the values of the text from those when you call your signIn function.