如何解决Flutter正在将数据发送到Firebasecupertinopicker的问题
首先对不起,我的英语不好,我才开始学习Flutter。 所以我想在Firestore中获取所有信息,但无法解决这些问题。
问题1:
如果我单击选择按钮,则将显示Cupertinopicker,结果将显示在按钮旁边。因此,如果我选择b,我希望将结果发送到Firestore。而且我不知道我该如何...使用Cupertinopicker ... 我也想知道如何使用验证器并显示错误符号 enter image description here
这是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],SizedBox(
height: 20.0,],
问题2 :我希望将所有电子邮件,密码,名称,字母(带有铜币的人)发送到Firestore用户。因此,我想将其放在[用户字段]中,我也被卡在这里。
这是下面的“注册”按钮。
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),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),
我需要使用哪个代码...。 如果有人帮助我,那将是非常有帮助的。 非常感谢
解决方法
我假设您已经了解如何在Flutter中使用Firebase。
对于第一个问题,您要做的就是在
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;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。