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

问题描述 投票:-1回答:1

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

我目前正在使用电子邮件和密码进行身份验证,但我也想将NewUsers给出的数据从注册到应用程序时自动注册到Firebase。

我看到Firebase具有displayNameUIDPhoneNumber。这些是唯一的吗?它没有说明如何从注册屏幕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);
                  }
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
firebase flutter dart username
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.