在Flutter应用中创建新用户时,出现firebase_auth createUserWithEmailAndPassword错误

时间:2019-04-21 17:47:01

标签: flutter flutter-dependencies

我正在创建博客应用,而在创建新用户时却遇到了错误。

  

I / flutter(1603):'file:/// C:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.8.4+5/lib/src/firebase_auth.dart' :断言失败:第103行pos 12:'email!= null':不正确。

当我想在flutter应用程序中创建新用户时,以上消息就会显示在终端中。

下面是我的创建帐户页面的代码,在该页面中,我已使用UserManagement()函数将用户数据存储在Firestore中。

Padding(
                        padding:
                            const EdgeInsets.fromLTRB(25.0, 10.0, 25.0, 10.0),
                        child: TextFormField(
                          decoration: InputDecoration(
                              labelText: "E-mail",
                              border: OutlineInputBorder(
                                  gapPadding: 10.0,
                                  borderRadius: BorderRadius.circular(30.0))),
                          onSaved: (value) {
                            setState(() {
                              _email = value;
                            });
                          },),
                      ),
                      Padding(
                        padding:
                            const EdgeInsets.fromLTRB(25.0, 10.0, 25.0, 10.0),
                        child: TextFormField(
                          obscureText: true,
                          decoration: InputDecoration(
                              labelText: "Password",
                              border: OutlineInputBorder(
                                  gapPadding: 10.0,
                                  borderRadius: BorderRadius.circular(30.0))),
                                   onSaved: (value) {
                            setState(() {
                              _password = value;
                            });
                          },
                ),
              ),
              Container(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    StreamBuilder<Object>(
                        stream: null,
                        builder: (context, snapshot) {
                          return SizedBox(
                              width: 367.0,
                              height: 60.0,
                              // Padding(
                              //   padding: const EdgeInsets.all(8.0),
                              child: RaisedButton(
                                child: Text("Next",
                                    style: TextStyle(
                                        color: Colors.white,
                                        fontWeight: FontWeight.w300)),
                                color: Colors.black54,
                                onPressed: () {
                                  if (_formkey.currentState
                                      .validate()) {
                                        FirebaseAuth.instance.createUserWithEmailAndPassword(
                                          email: _email,
                                          password: _password,
                                        ).then((signedInUser){
                                          UserManagement().storeNewUser(signedInUser, context);

                                        }).catchError((e){
                                          print(e);
                                        });

这是UserManagement()函数的代码

class UserManagement {
  storeNewUser(user, context) {
    Firestore.instance.collection('/users').add({
      'email': user.email,
      'uid': user.uid,
    }).then((value) {
      StreamBuilder<Object>(
          stream: null,
          builder: (context, snapshot) {
            Navigator.of(context).pop();
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => Desc()));
          });
    }).catchError((e) {
      print(e);
    });
  }
}

0 个答案:

没有答案