我发现很难使表单的内容将用户信息存储到Firebase数据库中。 每当我想在Flutter应用中实现Firebase crud时都会出错,每当我单击“创建”时,都会不断出现错误。
D / libc(3252):从pid = 3252调用getaddrinfo D / libc(3252):从pid = 3252调用的getaddrinfo W / RepoOperation(3252):/ users / -LWybBYyVil7rVlGdFCr的setValue失败:数据库错误:权限被拒绝< / p>
我的一些代码:
final FirebaseDatabase firebaseDatabase = FirebaseDatabase.instance;
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final DatabaseReference database =FirebaseDatabase.instance.reference().child('userprofile');
class MySplashScreenState extends State<MySplashScreen> {
final _stateController = TextEditingController();
final _languageController = TextEditingController();
final _sexController = TextEditingController();
String _fname = '';
String _lname = '';
String _email = '';
@override
void initState() {
super.initState();
firebaseAuth.currentUser().then((curUser){
print(curUser.email);
_email = curUser.email;
});
}
new TextField(
controller: _languageController,
keyboardType: TextInputType.text,
decoration: new InputDecoration(
labelText: 'Official Language',
hintText: 'English, French',
icon: new Icon(Icons.language)),
onChanged: (val) {
setState(() {
_language = val;
});
},
),
Future postData() async {
var users = new Userprofile(fname: _fname, lname: _lname, state: _state, language: _language, gender: _gender);
firebaseDatabase.reference().child('users').push().set(
users.toJson());
_firstNameCtrlr.text = '';
_lastNameCtrlr.text = '';
_stateController.text= '';
return;
}