title: Condition (&&) not executing due to image (from firebase) not being detected when login. It works when the image is deleted and upload again
body: <p>I am trying to upload a set of data into the firebase database with a condition. In order to make it work, i have to delete the picture and upload it again. Can someone please advise why is this happening? Shouldn't it automatically refresh when i login and work how it supposed to?</p>
  <p>Here are the codes: -</p>
  <p>When i press this elevated button, it supposed to check the functionality &lt;=99.0 &amp;&amp; pickedImage != null.</p>
  <pre><code>      // 'Save' Elevated button
              
              Padding(
                                                  padding: const EdgeInsets.all(8.0),
                                                  child: ElevatedButton.icon(
                                                      label: const Text('Save'),
                                                      icon:
                                                          const Icon(Icons.save_alt_rounded),
                                                      onPressed: () async {
                                                        if (functionality &lt;=99.0 &amp;&amp; pickedImage != null) {
                                                          final uploadData = {
                                                            'Project': widget.value1,
                                                            'Station': widget.value2,
                                                            'Name': widget.value3,
                                                            'Facility': widget.value4,
                                                            'DateTime': dateTimeEsc,
                                                            'Total In Service':
                                                                totalInService,
                                                            'Functionality (%)':
                                                                functionality,
                                                          };
                                                          await FirebaseFirestore.instance
                                                              .collection('kgl')
                                                              .doc(widget.value2 +
                                                                  widget.value4)
                                                              .update(uploadData);
                                                        }
                                                      })),
              
             
           // pickedImage codes: - 
              
               @override
                State&lt;EscalatorScreen&gt; createState() =&gt; _EscalatorScreenState();
              XFile? pickedImage;
              var functionality;
              
              // Select and image from the gallery or take a picture with the camera
              // Then upload to Firebase Storage
                Future&lt;void&gt; _upload(String inputSource) async {
                  final picker = ImagePicker();
              
              
                  try {
                    pickedImage = (await picker.pickImage(
                        source: inputSource == 'camera'
                            ? ImageSource.camera
                            : ImageSource.gallery,
                        maxWidth: 1920));
              
                    final String fileName = path.basename(pickedImage!.path);
                    File imageFile = File(pickedImage!.path);
              
                    try {
              // Uploading the selected image 
              
                      await FirebaseStorage.instance
                          .ref(widget.value2)
                          .child(widget.value4)
                          .child(fileName)
                          .putFile(
                              imageFile,
                              SettableMetadata(customMetadata: {
                                'Station': widget.value2,
                                'Facility': widget.value4,
                              }));
              
                      // Refresh the UI
                      setState(() {});
                    } on FirebaseException catch (error) {
                      if (kDebugMode) {
                        debugPrint(error.toString());
                      }
                    }
                  } catch (err) {
                    if (kDebugMode) {
                      debugPrint(err.toString());
                    }
                  }
                }
              
              // Retrieve the uploaded images
              // This function is called when the app launches for the first time or when an image is uploaded or deleted
              
                Future&lt;List&lt;Map&lt;String, dynamic&gt;&gt;&gt; _loadImages() async {
                  List&lt;Map&lt;String, dynamic&gt;&gt; files = [];
              
                  final ListResult result = await FirebaseStorage.instance
                      .ref(widget.value2)
                      .child(widget.value4)
                      .list();
                  final List&lt;Reference&gt; allFiles = result.items;
              
                  await Future.forEach&lt;Reference&gt;(allFiles, (file) async {
                    final String fileUrl = await file.getDownloadURL();
                    //final FullMetadata fileMeta = await file.getMetadata();
                    files.add({
                      'url': fileUrl,
                      'path': file.fullPath,
                      
                    });
                  });
              
                  return files;
                }
              
                Future&lt;void&gt; _delete(String ref) async {
                  await FirebaseStorage.instance.ref(ref).delete();
                  setState(() {});
                }
      
      Row(
                                          children: [
                                            Flexible(
                                              child: FutureBuilder(
                                                future: _loadImages(),
                                                builder: (context,
                                                    AsyncSnapshot&lt;
                                                            List&lt;
                                                                Map&lt;String, dynamic&gt;&gt;&gt;
                                                        snapshot) {
                                                  if (snapshot.connectionState ==
                                                      ConnectionState.done) {
                                                    return ListView.builder(
                                                      itemExtent: 320,
                                                      scrollDirection: Axis.vertical,
                                                      shrinkWrap: true,
                                                      itemCount:
                                                          snapshot.data?.length ?? 0,
                                                      itemBuilder: (context, index) {
                                                        final Map&lt;String, dynamic&gt;
                                                            image =
                                                            snapshot.data![index];
      
                                                        return Column(
                                                          children: [
                                                            Image.network(
                                                              image['url'],
                                                              width: 300,
                                                              height: 250,
                                                              fit: BoxFit.cover,
                                                            ),
                                                            const SizedBox(height: 5),
                                                            IconButton(
                                                              onPressed: () =&gt;
                                                                  _delete(
                                                                      image['path']),
                                                              icon: const Icon(
                                                                Icons.delete,
                                                                color: Colors.red,
                                                              ),
                                                            ),
                                                          ],
                                                        );
                                                      },
                                                    );
                                                  }
                                                  return const Center(
                                                    child:
                                                        CircularProgressIndicator(),
                                                  );
                                                },
                                              ),
                                            ),
                                          ],
                                        )
  
  Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceAround,
                                    children: [
                                      ElevatedButton.icon(
                                          onPressed: () =&gt; _upload('camera'),
                                          icon: const Icon(Icons.camera),
                                          label: const Text('camera')),
                                      ElevatedButton.icon(
                                          onPressed: () =&gt; _upload('gallery'),
                                          icon: const Icon(Icons.library_add),
                                          label: const Text('Gallery')),
                                    ],
                                  ),
  
  \\ functionality codes
  
  child: FutureBuilder&lt;DocumentSnapshot&gt;(
                            future: kgl.doc(widget.value2 + widget.value4).get(),
                            builder: (context, snapshot) {
                              if (!snapshot.hasData) {
                                return const CircularProgressIndicator();
                              }
  
                              Map&lt;String, dynamic&gt; data =
                                  snapshot.data!.data() as Map&lt;String, dynamic&gt;;
                              var totalInService =
                                  data['Total Units'] - data['Total OOS'];
                              functionality = ((100 / data['Total Units']) *
                                      (data['Total Units'] - data['Total OOS']))
                                  .ceilToDouble();
                              final comments = data['Comments'];
  
                              return Column(
                                children: [
                                  ListTile(
                                      title: const Text('Total Units:'),
                                      subtitle: Text('${data['Total Units']}'),
                                      trailing: SizedBox(
                                        width: 100,
                                        child: Row(
                                          children: [
                                            IconButton(
                                                icon: const Icon(Icons.edit),
                                                onPressed: () {
                                                  _updateTotalUnits();
                                                }),
                                          ],
                                        ),
                                      )),
                                  ListTile(
                                      title: const Text('Total OOS:'),
                                      subtitle: Text('${data['Total OOS']}'),
                                      trailing: SizedBox(
                                        width: 100,
                                        child: Row(
                                          children: [
                                            IconButton(
                                                icon: const Icon(Icons.edit),
                                                onPressed: () {
                                                  _updateTotalOOS();
                                                }),
                                          ],
                                        ),
                                      )),
                                  ListTile(
                                      title: const Text('Comments:'),
                                      subtitle: Text(comments),
                                      trailing: SizedBox(
                                        width: 100,
                                        child: Row(
                                          children: [
                                            IconButton(
                                                icon: const Icon(Icons.edit),
                                                onPressed: () {
                                                  _updateComments();
                                                }),
                                          ],
                                        ),
                                      )),
                                  ListTile(
                                    title: const Text('Total In Service:'),
                                    subtitle: Text('$totalInService'),
                                  ),
                                  Card(
                                    elevation: 100,
                                    shadowColor: Colors.black,
                                    child: Container(
                                      color: getColor(),
                                      padding: const EdgeInsets.symmetric(
                                          vertical: 10, horizontal: 80),
                                      child: Text(
                                        'Functionality: $functionality %',
                                        style: const TextStyle(
                                          fontSize: 20,
                                        ),
                                      ),
                                    ),
                                  ),
  </code></pre>
  <p><a href="https://i.stack.imgur.com/4Onro.png" rel="nofollow noreferrer">The app snapshot</a></p>