[英]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.