How to update boolean value in Firestore from a switch tile?
You could improve your updateNotifications()
function to not have duplicate code:
Future<void> updateNotifications() async {
await FirebaseFirestore.instance
.collection('userNotifications')
.doc(currentSignedInUserID)
.update({
'messages': notificationsActive,
});
setState(() {
notificationsActive = !notificationsActive;
});
}
And also I would suggest to you to listen to your Firestore collection and update UI on change. You can look up on how to do that here.