我想为Flutter应用程序使用Firestore,但抛出错误。它抛出[core/no-options] Firebase:当未通过源部署到宿主时,需要提供选项。另请参阅:https://futter.dev/docs/testing/errors。也不会让整个脚手架承受荷载。
try {
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email!.text, password: pass!.text);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => Home(),
),
);
FirebaseFirestore.instance
.collection('userdata')
.doc(u_name?.text)
.get()
.then(
(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
final snackBar = SnackBar(
content: const Text('Username already been taken.'),
backgroundColor: (Colors.black12),
action: SnackBarAction(
label: 'Dismiss',
onPressed: () {},
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
} else {
FirebaseFirestore.instance
.collection('userdata')
.doc(u_name?.text)
.set(
{
'f_name': f_name?.text,
'l_name': l_name?.text,
'username' : u_name?.text,
'email' : email?.text,
'pass' : pass?.text,
},
);
}
},
);
}
1条答案
按热度按时间qco9c6ql1#
在使用任何其他Firebase服务之前,必须初始化Firebase应用程序,因此请确保首先调用initializeApp()函数,如How can I provide options when not being deployed to hosting via source?中所述