title: How to update boolean value in Firestore from a switch tile?
body: <p>My goal is to have a userNotifications collection in Firestore that is used to track user notification preferences.  The user can toggle between true and false based on tapping a switch tile.  With the code below, Firestore is immediately and correctly updating the boolean value based on user interaction and the user interface is updating and reflecting the changes.  If the user logs out and logs back in, the boolean value is accurately reflected in the user interface.</p>
  <p>Before I apply this approach more broadly in the code I was hoping that someone can comment and let me know if my approach to updating the boolean value in Firestore is valid or point me in a better direction so I can improve my code.  Links to SO posts or documentation are fine as I am more than willing to read and learn.  Thanks in advance for any help.</p>
  <pre><code>class NotificationsMessagesTile extends StatefulWidget {
  
    const NotificationsMessagesTile({
      Key? key,
    }) : super(key: key);
  
    @override
    State&lt;NotificationsMessagesTile&gt; createState() =&gt;
        _NotificationsMessagesTileState();
  }
  
  class _NotificationsMessagesTileState extends State&lt;NotificationsMessagesTile&gt; {
    bool notificationsActive = false;
    final String? currentSignedInUserID = Auth().currentUser?.uid;
  
    Future&lt;void&gt; updateNotifications() async {
      if (!notificationsActive) {
        notificationsActive = true;
        FirebaseFirestore.instance
            .collection('userNotifications')
            .doc(currentSignedInUserID)
            .update({
          'messages': false,
        });
      } else {
        notificationsActive = false;
        FirebaseFirestore.instance
            .collection('userNotifications')
            .doc(currentSignedInUserID)
            .update({
          'messages': true,
        });
      }
      setState(() {});
    }
  
    @override
    Widget build(BuildContext context) {
      return SwitchListTileSliver(
        icon: Provider.of&lt;NotificationsPageProvider&gt;(context).areMessagesTurnedOn
            ? Icons.notifications_active
            : Icons.notifications_off,
        onChanged: (bool value) {
          final provider = Provider.of&lt;NotificationsPageProvider&gt;(
            context,
            listen: false,
          );
          provider.updateMessagesSettings(isOn: value);
          updateNotifications();
        },
        subTitle:
        Provider.of&lt;NotificationsPageProvider&gt;(context).areMessagesTurnedOn
            ? const Text(
          SettingsPageString.messagesOn,
        )
            : const Text(
          SettingsPageString.messagesOff,
        ),
        title: SettingsPageString.messages,
        value:
        Provider.of&lt;NotificationsPageProvider&gt;(context).areMessagesTurnedOn,
      );
    }
  }
  </code></pre>