flutter - 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),
)
],
),
),
);
});
}
}
解决方案
不知道这是做什么的
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});
推荐阅读
- c++ - 如何使用尾随反斜杠对字符串进行字符串化
- python - 在 Python 3 中,如何在同一行上打印多个表达式?
- python - 如何提高pytesseract的结果?
- php - PHP While循环将数据分成列
- r - 在 R 中导入和组合具有不同行数和名称的多个 CSV 文件
- python - 加载完所有缓冲区后如何加载我的 vim python 脚本?
- python-3.x - 更改python数据框中的日期时间格式
- swift - 自定义按钮子视图不显示
- java - Android 片段错误:找不到片段的 id 0x7f08009e (com.example.myapplication:id/preferenceFragment) 的视图
- qt - 如何获取 QTextEdit 文本和滚动条大小?