You can try with the below lines
BuildContext buildContext;
_phoneExist(phone) {
if (loading) {
showDialog(
context: context,
builder: (BuildContext context) {
buildContext = context; // Assign your context to buildcontext
return Center(
child: SpinKitChasingDots(color: Colors.brown,size: 50.0,
),
);
});
}
firestoreInstance
.collection("partners").where("phone", isEqualTo: phone).getDocuments()
.then((value) {
value.documents.forEach((result) {
if (result.exists) {
setState(() {
_userExist = true;
loading = false;
SchedulerBinding.instance.addPostFrameCallback((_) {
Navigator.pop(buildContext);
}); // By adding this you can close your pop up
});
} else {
}
});
});
if (_userExist) {
Scaffold.of(context).showSnackBar(snackBar2('$phone Aleady Exists'));
setState(() {
_userExist = false;
});
} else {
// _registerUser();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…