简体   繁体   English

如何使用 Dart 将新用户推送到 Firebase 数据库?

[英]How do I push a new user to a Firebase Database using Dart?

I'm trying add a new user to the database (pictured below) but I'm having difficulty pushing the data to the db.我正在尝试向数据库添加一个新用户(如下图所示),但我在将数据推送到数据库时遇到了困难。 I already have firebase authentication setup and that works fine.我已经有 firebase 身份验证设置,并且工作正常。 When a new user registers they are added to the authenticated list but not the db and I would like it to do both.当一个新用户注册时,他们会被添加到经过身份验证的列表中,但不会被添加到数据库中,我希望它两者都做。 What is the best way to do this?做这个的最好方式是什么?

Thanks!谢谢!

RaisedButton(
                        color: Colors.lightBlue,
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
                        padding: EdgeInsets.all(20.0),
                        child: Text(
                          'Register',
                          style: TextStyle(color: Colors.white, fontSize: 20.0),
                        ),
                        onPressed: () async {
                          if (_formKey.currentState.validate()) {
                            dynamic result = await _auth
                                .registerWithEmailAndPassword(email, password);
                              final userReference = FirebaseDatabase.instance.reference().child('users');
                              userReference.push().set({
                                'email': email,
                                'firstname': fname,
                                'lastname': lname,
                                'chatrooms': cRoomsList,
                                'showsList': showsList,
                              });

在此处输入图像描述

Instead of using the method _auth.registerWithEmailAndPassword(email, password);而不是使用方法_auth.registerWithEmailAndPassword(email, password); , ,
try using: _auth.createUserWithEmailAndPassword(email: email, password: password);尝试使用: _auth.createUserWithEmailAndPassword(email: email, password: password); , this method will also return the reference to the user. ,这个方法也会把引用返回给用户。

Let me know if this helps!让我知道这是否有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Flutter 中的 Firebase 中创建新用户 - How do I create a new user in Firebase in Flutter 如何将 displayName 添加到 Firebase 用户? (颤振/飞镖) - How can I add the displayName to the Firebase user? (Flutter/Dart) 如何使用 Flutter/Dart 从 Firebase 实时数据库中读取数据 - How to read data from Firebase Realtime database using Flutter/Dart 如何从 Flutter 中的 Firebase 实时数据库中获取我最近推送 ID 的密钥? - How do I get the key of my most recent push ID from Firebase Realtime Database in Flutter? 如何删除用户在使用其 uid 代码时创建的 firebase 中的文档。 飞镖代码“颤振” - How can i delete a document in firebase which the user has created while using their uid code. Dart code 'Flutter' 如何从 Dart VM / Dart 集成测试访问 Firebase Firestore? - How do I access Firebase Firestore from Dart VM / Dart integration tests? 如何在 Dart 应用程序中使用 Mockito 模拟 Firebase Crashlytics? - How can I mock Firebase Crashlytics using Mockito in a Dart app? 每次在 firebase 实时数据库中添加新子时,使用 firebase 函数发送推送通知不起作用 - sending push notification using firebase functions every time a new child is added in firebase realtime database is not working 如何将所有文档显示为来自 firestore 数据库的对象,并从用户输入(Flutter/Dart)中检索给定的过滤器? - How do I display all document as objects from firestore database, with given filters retrieved from user input (Flutter/Dart)? Flutter、Dart 和 FirebaseAuth:如何将标志链接到用户? - Flutter, Dart and FirebaseAuth: How do I link a sign to a user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM