Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何注册用户,并在注册页面中自动链接一些特定于用户的数据?_Firebase_Flutter_Dart - Fatal编程技术网

Firebase 如何注册用户,并在注册页面中自动链接一些特定于用户的数据?

Firebase 如何注册用户,并在注册页面中自动链接一些特定于用户的数据?,firebase,flutter,dart,Firebase,Flutter,Dart,如何在注册屏幕中注册用户并自动链接一些特定于用户的数据,如“用户名” 我目前正在使用电子邮件和密码进行身份验证,但我还希望在进入我的应用程序时将新用户提供的数据从注册自动存储到Firebase 我看到Firebase有displayName、UID和PhoneNumber。只有这些吗?它没有说明如何从注册屏幕UI颤振启动它 class RegistrationScreen extends StatefulWidget { static const String id = 'registrat

如何在注册屏幕中注册用户并自动链接一些特定于用户的数据,如“用户名”

我目前正在使用电子邮件和密码进行身份验证,但我还希望在进入我的应用程序时将
新用户
提供的数据从注册自动存储到Firebase

我看到Firebase有
displayName
UID
PhoneNumber
。只有这些吗?它没有说明如何从注册屏幕UI颤振启动它

class RegistrationScreen extends StatefulWidget {
  static const String id = 'registration_screen';

  @override
  _RegistrationScreenState createState() => _RegistrationScreenState();
}

class _RegistrationScreenState extends State<RegistrationScreen> {
  final _auth = FirebaseAuth.instance;
  bool showSpinner = false;
  String email;
  String password;

  String displayName;

  String userTelephoneNumer;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: ModalProgressHUD(
        inAsyncCall: showSpinner,
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 24.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Flexible(
                child: Hero(
                  tag: 'logo',
                  child: Container(
                    height: 200.0,
                    child: Image.asset('images/logo.png'),
                  ),
                ),
              ),
              SizedBox(
                height: 18.0,
              ),
              TextField(
                keyboardType: TextInputType.emailAddress,
                textAlign: TextAlign.center,
                onChanged: (value) {
                  displayName = value;
                },
                decoration:
                    kTextFieldDecoration.copyWith(hintText: 'Enter your UserName'),
              ),
              SizedBox(
                height: 8.0,
              ),
              // TextField(
              //   keyboardType: TextInputType.emailAddress,
              //   textAlign: TextAlign.center,
              //   onChanged: (value) {

              //     userTelephoneNumer = value;
              //   },
              //   decoration:
              //       kTextFieldDecoration.copyWith(hintText: 'Enter your Telephone Number'),
              // ), SizedBox(
              //   height: 8.0,
              // ),
              SizedBox(
                height: 48.0,
              ),
              TextField(
                keyboardType: TextInputType.emailAddress,
                textAlign: TextAlign.center,
                onChanged: (value) {
                  email = value;
                },
                decoration:
                    kTextFieldDecoration.copyWith(hintText: 'Enter your email'),
              ),
              SizedBox(
                height: 8.0,
              ),
              TextField(
                obscureText: true,
                textAlign: TextAlign.center,
                onChanged: (value) {
                  password = value;
                },
                decoration: kTextFieldDecoration.copyWith(
                    hintText: 'Enter your password'),
              ),
              SizedBox(
                height: 24.0,
              ),
              RoundedButton(
                title: 'Register',
                colour: Colors.blueAccent,
                onPressed: () async {
                  setState(() {
                    showSpinner = true;
                  });
                  try {

                    final newUser = await _auth.createUserWithEmailAndPassword(
                        email: email, password: password, );
                    if (newUser != null) {

                    print(displayName);

                    print(userTelephoneNumer);
                      Navigator.pushNamed(context, MapScreen.id);
                    }

                    setState(() {
                      showSpinner = false;
                    });
                  } catch (e) {
                    print(e);
                  }
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
类注册屏幕扩展StatefulWidget{
静态常量字符串id='registration_screen';
@凌驾
_RegistrationScreenState createState()=>_RegistrationScreenState();
}
类注册状态扩展状态{
final _auth=FirebaseAuth.instance;
bool showSpinner=false;
字符串电子邮件;
字符串密码;
字符串显示名;
字符串用户电话号码;
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.white,
正文:ModalProgressHUD(
inAsyncCall:showSpinner,
孩子:填充(
填充:边缘组。对称(水平:24.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
灵活的(
孩子:英雄(
标签:“logo”,
子:容器(
高度:200.0,
子项:Image.asset('images/logo.png'),
),
),
),
大小盒子(
身高:18.0,
),
文本字段(
键盘类型:TextInputType.emailAddress,
textAlign:textAlign.center,
一旦更改:(值){
显示名称=值;
},
装饰:
kTextFieldDecoration.copyWith(hintText:“输入您的用户名”),
),
大小盒子(
身高:8.0,
),
//文本字段(
//键盘类型:TextInputType.emailAddress,
//textAlign:textAlign.center,
//一旦更改:(值){
//userTelephoneNumer=值;
//   },
//装饰:
//kTextFieldDecoration.copyWith(hintText:“输入您的电话号码”),
//),大小框(
//身高:8.0,
// ),
大小盒子(
身高:48.0,
),
文本字段(
键盘类型:TextInputType.emailAddress,
textAlign:textAlign.center,
一旦更改:(值){
电子邮件=价值;
},
装饰:
kTextFieldDecoration.copyWith(hintText:“输入您的电子邮件”),
),
大小盒子(
身高:8.0,
),
文本字段(
蒙昧文字:对,
textAlign:textAlign.center,
一旦更改:(值){
密码=值;
},
装饰:kTextFieldDecoration.copyWith(
hintText:“输入密码”),
),
大小盒子(
身高:24.0,
),
圆形按钮(
标题:'登记',
颜色:颜色。蓝色口音,
onPressed:()异步{
设置状态(){
showSpinner=true;
});
试一试{
final newUser=wait_auth.createUserWithEmailAndPassword(
电子邮件:电子邮件,密码:密码,);
if(newUser!=null){
打印(显示名称);
打印(用户电话号码);
Navigator.pushName(上下文,MapScreen.id);
}
设置状态(){
showSpinner=false;
});
}捕获(e){
印刷品(e);
}
},
),
],
),
),
),
);
}
}

Firebase身份验证不具备按用户存储通用自由格式数据的能力。你应该使用一个数据库。Firbase Auth将为用户提供一个UID,您可以将该UID用作数据库的索引,以存储每个用户的数据


您可以选择的数据库不受限制。Firebase有两个选项(实时数据库和Firestore),但您可以使用任何选择。

Ok,这很有意义。那么这是否意味着我首先在Firebase上建立数据库,然后在Flatter中操作它?不知道如何将用户UID与新用户的数据库连接起来,而不单独执行每个数据库自由形式,然后将其作为流获取。是的,您必须这样做。是否有文档可供漫游?不确定从何处开始,以及在引用新数据库连接时使用什么关键字。有大量用于各种客户端平台的Firebase数据库的文档和示例。我建议从网络搜索开始。