title: Trying to build a Like/Unlike Button in Flutter Streambuilder - not working
body: <p>I am trying to get a like/unlike button in a newsfeed I am building in my app. I'm using streambuilder.</p>
  <p>Here's the code for the button:</p>
  <pre><code>FlatButton(
                                child: Container(
                                  child: Column(
                                    children: &lt;Widget&gt;[
                                      Icon(
                                        Icons.thumb_up,
                                        color: Colors.black,
                                      ),
                                      Text(
                                        'Like',
                                        style: TextStyle(fontSize: 12.0),
                                      ),
                                    ],
                                  ),
                                ),
                                onPressed: isPostLiked == true ? () {
                                  _firestore.collection('posts').document(postID).updateData({'likeCount' : postLikeCount - 1, 'likedBy' : FieldValue.arrayRemove(['${loggedInUser.email}'])});
  
  
                                  isPostLiked = false;
                                  print('USER HAS UNLIKED THIS POST');
  
                                } : () {
                                  _firestore.collection('posts').document(postID).updateData({'likeCount' : postLikeCount + 1, 'likedBy' : FieldValue.arrayUnion(['${loggedInUser.email}'])});
  
                                  isPostLiked = true;
                                  print('USER HAS LIKED THIS POST');
  
                                },
                              ),
  </code></pre>
  <p>The isPostLiked is a bool, which I've set initially to be false <code>bool isPostLiked = false;</code>.</p>
  <p>The issue that I have is that its only letting the user like post. It won't let the user unlike the post. It seems that its just not updating the <code>isPostLiked = true</code>, and that seems to be where I am going wring. Any ideas?</p>
  <p>For a bit more context, here's some of the code of the Streambuilder widget that the FlatButton is nested in:</p>
  <pre><code>StreamBuilder&lt;QuerySnapshot&gt;(
                stream: _firestore
                    .collection('posts')
                    .orderBy('date', descending: true)
                    .snapshots(),
                builder: (context, snapshot) {
                  if (!snapshot.hasData) {
                    return Center(
                      child: CircularProgressIndicator(
                        backgroundColor: Colors.lightBlueAccent,
                      ),
                    );
                  }
                  final posts = snapshot.data.documents;
                  List&lt;Widget&gt; postWidgets = [];
                  for (var post in posts) {
                    bool isPostLiked = false;
  ...
  </code></pre>
  <p>Thanks in advance for your help!</p>