1

首先抱歉我的英语不好,我刚开始学习 Flutter。所以我想在 Firestore 中获取所有信息,但我无法解决这些问题。

问题一:

如果我单击选择按钮,Cupertinopicker 将显示,结果将显示在按钮旁边。所以如果我选择 b,我希望将结果发送到 Firestore。而且我不知道如何使用 CupertinoPicker... 我还想知道如何使用验证器并显示错误符号 在此处输入图像描述

这是下面带有 Cupertinopicker 的代码。我想要将 Text(_countryType[_selectedIndex] 发送到 Firebase。

 Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              CupertinoButton(
                borderRadius: BorderRadius.circular(29.0),
                color: kPrimaryColor,
                padding: const EdgeInsets.all(12.0),
                child: Text(
                  "select",
                  style: TextStyle(fontSize: 16.0),
                ),
                onPressed: () {
                  showModalBottomSheet(
                      context: context,
                      builder: (BuildContext context) {
                        return Container(
                          height: 170.0,
                          child: CupertinoPicker(
                              scrollController:
                                  new FixedExtentScrollController(
                                initialItem: _selectedIndex,
                              ),
                              itemExtent: 32.0,
                              onSelectedItemChanged: (int index) {
                                setState(() {
                                  _country = _countryType[index];
                                  _selectedIndex = index;
                                });
                              },
                              children: new List<Widget>.generate(
                                  _countryType.length, (int index) {
                                return new Center(
                                  child: new Text(_countryType[index]),
                                );
                              })),
                        );
                      });
                },
              ),
              Container(
                margin: EdgeInsets.symmetric(vertical: 17),
                width: 70,
                child: Center(
                  child: Text(
                    _countryType[_selectedIndex],
                    style: TextStyle(fontSize: 16.0),
                  ),
                ),
              ),
              SizedBox(
                height: 20.0,
              ),
            ],
          ),

问题2:我希望将所有电子邮件、密码、姓名、字母(带有 cupertinopicker 的那个)发送给 firestore 用户。所以我想把它放在[User-uid-fields]我也被困在这里。

这是下方的注册按钮。

Container(
            margin: EdgeInsets.symmetric(vertical: 10),
            width: size.width * 0.8,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(29),
              child: FlatButton(
                padding: EdgeInsets.symmetric(vertical: 20, horizontal: 40),
                color: kPrimaryColor,
                onPressed: () async {
                  try {
                    FirebaseUser user = (await FirebaseAuth.instance
                            .createUserWithEmailAndPassword(
                      email: _emailController.text,
                      password: _passwordController.text,
                    ))
                        .user;
                    if (user != null) {
                      UserUpdateInfo updateUser = UserUpdateInfo();
                      updateUser.displayName = _usernameController.text;
                      user.updateProfile(updateUser);
                      Navigator.of(context).pushNamed(AppRoutes.authLogin);
                    }
                  } catch (e) {
                    print(e);
                    _usernameController.text = "";
                    _passwordController.text = "";
                    _repasswordController.text = "";
                    _emailController.text = "";
                    
                  }
                  setState(() {
                    saveAttempted = true;
                  });
                  if (_formKey.currentState.validate()) {
                    _formKey.currentState.save();
                  }
                },
                
                child: Text(
                  "Sign Up",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          ),

我需要使用哪个代码....如果有人帮助我,那将非常有帮助..我压力很大。非常感谢

4

1 回答 1

0

我假设您了解如何将 Firebase 与 Flutter 一起使用的基础知识。
对于第一个问题,您需要做的就是在里面调用一个函数

                              onSelectedItemChanged: (int index) {
                            setState(() {
                              _country = _countryType[index];
                              _selectedIndex = index;
                            });
                          },

这里发生的是,每当您选择一个项目时。onSelectedItemChanged 被调用。所以你需要做的就是在这里调用一个函数
示例 -

                              onSelectedItemChanged: (int index) {
                            addToFirebase(_countryType[_selectedIndex]);
                            setState(() {
                              _country = _countryType[index];
                              _selectedIndex = index;
                            });
                          },

对于您的第二个问题,Firebase 身份验证不是这样工作的。用户详细信息存储在 Firebase 的身份验证区域中。您也看不到密码。要存储与用户关联的国家/地区类型,您可以使用用户 ID 作为键,因为它是唯一的。

                FirebaseUser user = (await FirebaseAuth.instance
                        .createUserWithEmailAndPassword(
                  email: _emailController.text,
                  password: _passwordController.text,
                ))
                    .user;
                String uid = user.uid;
于 2020-09-16T13:37:42.353 回答