title: Flutter/Firebase - Failed assertion: line 61 pos 12: 'field != null': is not true
body: <p>I am trying to create a log in page for my app linked to firebase. I have set up the desired fields and when I go to submit the form I recieve the following error:</p>
  <pre><code>I/flutter (17068): 'package:firebase_auth/src/firebase_auth.dart': Failed assertion: line 61 pos 12: 'email != null': is not true.
  </code></pre>
  <p>I have made sure that each of the fields when I run the simulator are filled but still can't work out why this won't work. Here is the code:</p>
  <pre><code>import 'package:easy_tiger/constants/appbar.dart';
  import 'package:easy_tiger/screens/account.dart';
  import 'package:easy_tiger/style.dart';
  import 'package:flutter/gestures.dart';
  import 'package:flutter/material.dart';
  import 'package:easy_tiger/services/auth_service.dart';
  
  enum AuthFormType { signIn, signUp }
  
  class SignUpPage extends StatefulWidget {
    final AuthFormType authFormType;
  
    SignUpPage({Key key, this.authFormType}) : super(key: key);
  
    @override
    _SignUpPageState createState() =&gt; _SignUpPageState(authFormType: this.authFormType);
  }
  
  class _SignUpPageState extends State&lt;SignUpPage&gt; {
    AuthFormType authFormType;
  
    _SignUpPageState({this.authFormType});
  
    final formKey = GlobalKey&lt;FormState&gt;();
    String _firstName,
        _lastName,
        _email,
        _confirmEmail,
        _password,
        _confirmPassword,
        _dateOfBirth;
  
    void switchFormState(String state) {
      formKey.currentState.reset();
      if(state == 'signUp') {
        setState(() {
          authFormType = AuthFormType.signUp;
        });
      } else {
        setState(() {
          authFormType = AuthFormType.signIn;
        });
      }
    }
  
    void submit() async {
      final form = formKey.currentState;
      form.save();
      try {
        final auth = Provider.of(context).auth;
        if(authFormType == AuthFormType.signIn) {
          String uid = await auth.signInWithEmailAndPassword(_email, _password);
          print(&quot;Signed In with ID $uid&quot;);
          Navigator.of(context).pushReplacementNamed('/home');
        } else {
          String uid = await auth.createUserWithEmailAndPassword(_firstName,
              _lastName, _email,_confirmEmail, _password, _confirmPassword,
          _dateOfBirth);
          print(&quot;Signed up with New ID $uid&quot;);
          Navigator.of(context).pushReplacementNamed('/home');
        }
      } catch (e) {
        print (e);
      }
    }
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        
          appBar: PreferredSize(
              preferredSize: const Size.fromHeight(80),
              child: MainAppBar(
                text: buildAppBarText(),
              )),
          body: SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(12.0),
              child: Center(
                child: Container(
                  child: Column(
                    children: &lt;Widget&gt;[
                      Align(
                        child: Text(buildTitleText(), style: AppBarTextStyle),
                      ),
                      Container(
                        padding: EdgeInsets.only(top: 10),
                      ),
                      Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: Form(
                            key: formKey,
                            child: Column(
                              children: buildInputs() + buildSwitchText(),
                            )),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ));
    }
  
    buildHeaderText() {
      String _headerText;
  
      if (authFormType == AuthFormType.signUp) {
        _headerText = &quot;Don't have an account?&quot;;
      } else {
        _headerText = &quot;Already have an account?&quot;;
      } return _headerText;
    }
  
    List&lt;Widget&gt; buildInputs() {
      List&lt;Widget&gt; textFields = [];
  
      if (authFormType == AuthFormType.signIn) {
        textFields.add(TextFormField(
          style: TextStyle(
            fontSize: 12.0,
          ),
          decoration: buildSignUpInputDecoration('Email'),
          onSaved: (value) =&gt; _email
        ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Password'),
      obscureText: true,
      onSaved: (value) =&gt; _password,
      ),);
      }
      else {
        //if we're in the sign up state, add name
  
        // add email &amp; password
        textFields.add(TextFormField(
        style: TextStyle(
        fontSize: 12.0,
        ),
        decoration: buildSignUpInputDecoration('First Name'),
        onSaved: (value) =&gt; _firstName,
        ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Last Name'),
      onSaved: (value) =&gt; _lastName,
      ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Email Address'),
      onSaved: (value) =&gt; _email,
      ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Confirm Email Address'),
      onSaved: (value) =&gt; _confirmEmail,
      ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Password'),
      obscureText: true,
      onSaved: (value) =&gt; _password,
      ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Confirm Password'),
      onSaved: (value) =&gt; _confirmPassword,
      ));
        textFields.add(SizedBox(
          height: 15,
        ));
        textFields.add(TextFormField(
      style: TextStyle(
      fontSize: 12.0,
      ),
      decoration: buildSignUpInputDecoration('Date of Birth'),
      onSaved: (value) =&gt; _dateOfBirth,
      ));
        textFields.add(SizedBox(
          height: 15,
        ));
      }
        return textFields;
    }
  
    List&lt;Widget&gt; buildSwitchText() {
      String _switchButtonTextPart1, _switchButtonTextPart2,_newFormState;
  
      if(authFormType == AuthFormType.signIn) {
        _switchButtonTextPart1 = &quot;Haven't got an account? &quot;;
        _switchButtonTextPart2 = 'Sign Up';
        _newFormState = 'signUp';
      } else {
        _switchButtonTextPart1 = 'Already have an account? ';
        _switchButtonTextPart2 = 'Sign In';
        _newFormState = 'signIn';
      } return [
        SizedBox(height: 5.0),
        Container(
          width: MediaQuery.of(context).size.height * 0.7,
          child: RaisedButton(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0),),
              color: kPrimaryColor,
              textColor: Colors.black,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(_switchButtonTextPart2,
                style: TextStyle(fontFamily: FontNameDefault,
                fontSize: 15.0),),
              ),
              onPressed: submit),
        ),
        SizedBox(height: 5.0,),
      RichText(
        text: TextSpan(
            style: TextStyle(
              fontFamily: FontNameDefault,
              color: Colors.black,
              fontSize: 12.0,
            ),
            children: &lt;TextSpan&gt;[
              TextSpan(
                text: _switchButtonTextPart1
              ),
              TextSpan(
                  text: _switchButtonTextPart2,
                  style: TextStyle(
                      decoration: TextDecoration.underline,
                      color: Colors.black,
                      fontSize: 12.0),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      switchFormState(_newFormState);
                    })
            ]),
      ),
      ];
    }
  
    String buildAppBarText() {
      String _switchAppBarHeader;
  
      if(authFormType == AuthFormType.signIn) {
        _switchAppBarHeader = &quot;Already have an account?&quot;;
      } else {
        _switchAppBarHeader = &quot;Don't have an account?&quot;;
      } return
          _switchAppBarHeader;
    }
  
    String buildTitleText() {
      String _switchTextHeader;
  
      if(authFormType == AuthFormType.signIn) {
        _switchTextHeader = &quot;Sign In&quot;;
      } else {
        _switchTextHeader = &quot;Sign Up&quot;;
      } return
        _switchTextHeader;
    }
  
  
  }
  class AccountController extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      final AuthService auth = Provider.of(context).auth;
      return StreamBuilder(
          stream: auth.onAuthStateChanged,
          builder: (context, AsyncSnapshot&lt;String&gt; snapshot) {
            if (snapshot.connectionState == ConnectionState.active) {
              final bool signedIn = snapshot.hasData;
              return signedIn ? SignInPage() : SignUpPage();
            }
            return CircularProgressIndicator();
          });
    }
  }
  
  InputDecoration buildSignUpInputDecoration(String hint) {
    return InputDecoration(
      isDense: true,
      fillColor: Colors.white,
      hintText: hint,
      filled: true,
      enabledBorder: OutlineInputBorder(
        borderSide: BorderSide(width: 0.0),
      ),
      contentPadding: const EdgeInsets.only(left: 14.0, bottom: 10.0, top: 10.0),
    );
  }
  
  class Provider extends InheritedWidget {
    final AuthService auth;
  
    Provider({Key key, Widget child, this.auth}) : super(key: key, child: child);
  
    @override
    bool updateShouldNotify(InheritedWidget oldWidget) {
      return true;
    }
  
    static Provider of(BuildContext context) =&gt;
        context.dependOnInheritedWidgetOfExactType&lt;Provider&gt;();
  }
  </code></pre>