我尝试了很多方法来处理firestore中的异常,但我不能,请帮忙吗?假设在第127行我捕捉到错误并在屏幕上显示为showsnackbar
简单解决方案
ElevatedButton(
onPressed:()async{
if(_globalKey.currenState!.validate()){
try{
QuerySnapshot querSnapshot=await
FirebaseFirestore.collection("admin").doc("adminLogin").get();
if(querySnapshot.docs.isNotEmpty){
querySnapshot.docs.forEach((element){
if (element.data(['adminEmail'] == email && element.data()?
['adminPassword'] ==password) {
ScaffoldMessenger.of (context).showSnackbar( const SnackBar(
backgroundcolor: Colors.green, content: Text(
'Login success', textAlign: TextAlign.center, )));
Navigator.pushNamed (context, AdminScreen.id);
});
}
}
}catch(e){
}
}},
child:Text("login"))