首页 > 解决方案 > Flutter 未将新用户插入 Firebase

问题描述

在我的 Flutter 项目中,我正在尝试通过电子邮件密码注册新用户

在 Firebase 控制台中通过电子邮件密码启用了身份验证,但新用户未插入

Cloud Firestore中的其他数据已成功提取

调试控制台消息:当我在填写电子邮件后单击注册按钮并 I/BiChannelGoogleApi( 7328): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzao@b8e2d46 在此之后通过时没有任何反应:

在我的

发布规范.yaml

firebase_auth:^0.18.3

firebase_core:^0.5.2

这是我的代码:

signInSheet(BuildContext context) {
    return showModalBottomSheet(
        context: context,
        builder: (context) {
          return new Container(
            height: 400.0,
            width: 400.0,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(25.0),
                color: Color(0xFF191531)),
            child: Center(
              child: Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: TextField(
                      decoration: InputDecoration(
                          hintText: 'Enter email...',
                          hintStyle: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          )),
                      controller: emailController,
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: TextField(
                      obscureText: true,
                      decoration: InputDecoration(
                          hintText: 'Enter password...',
                          hintStyle: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          )),
                      controller: passwordController,
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: FloatingActionButton(
                        backgroundColor: Colors.redAccent,
                        child:
                            Icon(FontAwesomeIcons.check, color: Colors.white),
                        onPressed: () =>
                            Provider.of<Authentication>(context, listen: false)
                                .createNewAccount(emailController.text,
                                    passwordController.text)
                                .whenComplete(() {
                              if (Provider.of<Authentication>(context,
                                          listen: false)
                                      .getErrorMessage !=
                                  null) {
                                Navigator.pushReplacement(
                                    context,
                                    PageTransition(
                                        child: HomeScreen(),
                                        type: PageTransitionType.leftToRight));
                              } else {
                                Navigator.pushReplacement(
                                    context,
                                    PageTransition(
                                        child: Login(),
                                        type: PageTransitionType.leftToRight));
                              }
                            })),
                  ),
                  Text(
                    Provider.of<Authentication>(context, listen: true)
                        .getErrorMessage,
                    style: TextStyle(
                        color: Colors.white, fontWeight: FontWeight.bold),
                  )
                ],
              ),
            ),
          );
        });
  }
}

标签: flutterfirebase-authentication

解决方案


不知道这是做什么的

 Provider.of<Authentication>(context, listen: false)
                                .createNewAccount(emailController.text,
                                    passwordController.text)

无论如何,您需要的是,当使用电子邮件和密码成功创建用户时,您需要将条目添加到 firestore

//id obtained from current user instance
User user = FirebaseAuth.instance.currentUser;
 FirebaseFirestore.instance.collection("users").doc(user.id).set(
            {"username": "username, "phoneNo": "phone", "desc": "null","id":user.id});

推荐阅读