title: flutter, trying to update a picture from Storage
body: <p>I'm trying to upload, and update a picture from firebase storage. But for some reason this is not working properly.</p>
  <p>This would be the scenario; A user take a picture from his camera, so this picture is uploaded to my storage, so after that I get the <code>url</code> picture, so I can use this like <code>NetworkImage(url)</code> to update the picture.</p>
  <h2>This is what's happening currently:</h2>
  <hr />
  <p>Let's say I don't have any picture.</p>
  <ul>
  <li>I update my profile with a new picture. (This works perfectly).</li>
  </ul>
  <p>Now let's say I want to update my profile picture, so I take another picture, let's call it <code>A</code> so I upload this one.</p>
  <ul>
  <li>Nothing happens, picture doesn't change.</li>
  </ul>
  <p>But If I try again with a <code>B</code> picture, for some reason the picture is updated with the <code>A</code> picture.</p>
  <hr />
  <h2>This would be my code and how I'm facing this feature.</h2>
  <p>I have the next method which is invoked when a user click over his picture. I wait for the result (value) so when I got the result I upload the picture. Then, when the picture is uploaded, I just call to setState and save the <code>url</code> into the <code>_imageUrl</code> variable.</p>
  <p>After that, I change the &quot;profilePic&quot; attribute from my data base to <code>true</code>.</p>
  <pre><code>  String _imageUrl = 'assets/profileDefault.jpg';
    bool profilePicture = false;
    io.File profilePic;
    Future getFromCamara() async {
      await ImagePicker().getImage(source: ImageSource.camera).then((value) {
        profilePic = io.File(value.path);
        FirebaseStorage.instance.ref().child('picture').putFile(profilePic);
      }).then((result) {
        var ref = FirebaseStorage.instance.ref().child('picture');
        ref.getDownloadURL().then((loc) =&gt; setState(() =&gt; _imageUrl = loc));
      });
  
      try {
        FirebaseFirestore.instance
            .collection('Usuarios')
            .doc(uid)
            .update({'profilePic': true});
      } catch (e) {
        print(e.toString());
      }
  </code></pre>
  <p>So now, using a StreamBuilder, I get the result of <code>profilePic</code> from my DataBase, if is True, I download the URL, and if don't, I just use the Asset default's pic.</p>
  <pre><code>body: StreamBuilder(
          stream: FirebaseFirestore.instance.collection('Usuarios').snapshots(),
          builder: (context, AsyncSnapshot&lt;QuerySnapshot&gt; snapshot1) {
  
                if (!snapshot1.hasData) {
                  return Center(
                    child: CircularProgressIndicator(),
                  );
                }
  
                List&lt;DocumentSnapshot&gt; users = snapshot1.data.docs;
  
                for (DocumentSnapshot user in users) {
                  if (user.id == userID) {
                    profilePicture = user['profilePic'];
                  }
                }
  
                if (profilePicture) {
                  FirebaseStorage.instance
                      .ref()
                      .child('picture')
                      .getDownloadURL()
                      .then((loc) =&gt; _imageUrl = loc);
                } else {
                  _imageUrl = 'assets/profileDefault.jpg';
                }
               
                return Stack(
                  alignment: Alignment.center,
                  children: &lt;Widget&gt;[
                    Positioned(
                      top: 0,
                      child: Container(
                        color: Color.fromRGBO(255, 0, 0, 70),
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.height * .55,
                      ),
                    ),
                    Positioned(
                      top: MediaQuery.of(context).size.height * .015,
                      left: 15,
                      right: 15,
                      child: Container(
                        width: MediaQuery.of(context).size.height * .90,
                        height: 300,
                        padding: EdgeInsets.only(bottom: 10),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: &lt;Widget&gt;[
                            Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: &lt;Widget&gt;[
                                GestureDetector(
                                  onTap: () =&gt; _setPic(context),
                                  child: CircleAvatar(
                                    radius: 79,
                                    backgroundColor: Color(0xFFFFFFFFF),
                                    child: CircleAvatar(
                                      radius: 75,
                                      backgroundImage: profilePicture
                                          ? NetworkImage(_imageUrl)
                                          : AssetImage(_imageUrl),
                                    ),
                                  ),
                                ),
                              // More code...
  
  
  </code></pre>
  <p>What I'm doing wrong? Why my picture isn't getting updated?</p>
  <h2>Updated:</h2>
  <hr />
  <p>I tried this, so I can save in pictureTemp the picture's bytes, calling to setState to rebuild the widget and put the picture with <code>Image.memory(pictureTemp)</code>. But it doesn't seem to work.</p>
  <pre><code>  Uint8List pictureTemp;
    io.File profilePic;
    Future getFromCamara() async {
      var pickedFile = await ImagePicker().getImage(source: ImageSource.camera);
      var image = await pickedFile.readAsBytes();
  
      FirebaseStorage.instance
          .ref()
          .child('picture')
          .putFile(io.File(pickedFile.path));
  
      setState(() {
        pictureTemp = image;
      });
  </code></pre>
  <pre><code>child: CircleAvatar(
            radius: 75,
            backgroundImage: profilePicture
                 ? pictureTemp == null
                   ? AssetImage(_imageUrl)
                   : Image.memory(pictureTemp)
                 : AssetImage(_imageUrl),
         ),
  </code></pre>