title: How to add the toggle switch button from flutter to firebase firestore database
body: <p>I am trying to set up a toggle switch button from flutter to firestore. I have already set up the dependencies in my flutter project, however, I do not know how to connect the switch with the firestore.</p>
  
  <p>I am trying to make an on/off switch which can be used to control light; I have tried giving it some values but, even then, I am not sure how to connect with firestore.</p>
  
  <pre><code>class _HomeState extends State&lt;Home&gt; {
  
   bool _value = false;
  
    void _onChanged(bool value) {
     setState(() {
      _value = value; 
     });
  
    }
  
  
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Home ${widget.user.email}'),
        ),
        body: new Container(
          padding: new EdgeInsets.all(32.0),
          child: new Column(
            children: &lt;Widget&gt;[
              new SwitchListTile.adaptive(
                  title: new Text('Bedroom light'),
                  activeColor: Colors.red,
                  secondary: const Icon(Icons.lightbulb_outline),
                  value: _value,
                  onChanged: (bool value) {
                    _onChanged(value);
  
                  })
            ],
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p>This is the code I have so far. I know that we have to use StreamBuilder but I would like to know how.</p>