title: Flutter Image Picker retrieveLostData triggering my StreamBuilder so every couple of seconds it shows the loading screen?
body: <p>I got an app, I implemented a function where the user can select pictures from the gallery. The problem is when one of the user is trying to use this function, the app resets or something... Jumps back to the second screen from the 10th or something.</p>
  <p><a href="https://pub.dev/packages/image_picker" rel="nofollow noreferrer">image_picker</a> has a <code>retrieveLostData()</code> function that I tried to implement as the example shows. The problem is that on the screen where it jumps after reset I have a list what is getting built while using a stream. The <code>getLostData()</code> function is getting called every couple of seconds what makes my <code>StreamBuilder()</code> into <code>ConnectionState.waiting</code> so every couple of seconds the list disappear and the loading screen is showing...</p>
  <p>This is the <code>retrieveLostData()</code></p>
  <pre><code>Future&lt;void&gt; retrieveLostData() async {
      print(&quot;Retrieve Lost Data ${DateTime.now()}&quot;);
      final LostDataResponse response = await CustomImagePicker.imagePicker.retrieveLostData();
   
      if (response.file != null) {
        if (response.type == RetrieveType.video) {
  
        } else {
          if (response.file != null)
          _savePicture(response.file!);
        }
      } else {
        String retrieveDataError = response.exception!.code;
        LogsCompanion log = LogsCompanion.insert(message: &quot;IMAGE PROBLEM: ${retrieveDataError}&quot;, date: DateTime.now());
        _appDatabase.logDao.insertLog(log);
      }
    }
  </code></pre>
  <p>The <code>_savePicture()</code> part is not needed for you, nothing special happens. Here how the widgets are built:</p>
  <p>I just copy-pasted the code from the example:</p>
  <pre><code>return !kIsWeb &amp;&amp; defaultTargetPlatform == TargetPlatform.android
                  ? FutureBuilder&lt;void&gt;(
                      future: retrieveLostData(),
                      builder: (BuildContext context, AsyncSnapshot&lt;void&gt; snapshot) {
                        switch (snapshot.connectionState) {
                          case ConnectionState.none:
                          case ConnectionState.waiting:
                            return const Text(
                              'You have not yet picked an image.',
                              textAlign: TextAlign.center,
                            );
                          case ConnectionState.done:
                            return myPage();
                          default:
                            if (snapshot.hasError) {
                              return Text(
                                'Pick image/video error: ${snapshot.error}}',
                                textAlign: TextAlign.center,
                              );
                            } else {
                              return const Text(
                                'You have not yet picked an image.',
                                textAlign: TextAlign.center,
                              );
                            }
                        }
                      },
                    )
                  : WillPopScope(
                      child: myPage(),
                      onWillPop: () =&gt; _willPopCallBack(),
                    );
  </code></pre>
  <p>The actual screen looks like this:</p>
  <pre><code>StreamBuilder(
                initialData: [],
                stream: _appDatabase.myDao.getStream(),
                builder: (context, snapshot) {
                  if (snapshot.hasData &amp;&amp; snapshot.data!.length &gt; 0) {
                    return  ListView.separated(
                        separatorBuilder: (context, index) =&gt; Container(height: 8),
                        physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
                        itemCount: snapshot.data!.length,
                        itemBuilder: (context, index) {
                          return Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                               listItem(snapshot.data![index]),
                            ],
                          );
                      ),
                    );
                  }
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    print(&quot;ConnectionState waiting ${DateTime.now()}&quot;);
                    return CustomCircularProgressIndicator();
                  }
  
                  return RefreshIndicator(
                    onRefresh: ...
                          ),
                        ),
                      ),
                    ),
                  );
                },
              ),
  </code></pre>
  <p>The problem that it goes into this <code>if</code> even if the stream did not changed:</p>
  <pre><code>if (snapshot.connectionState == ConnectionState.waiting) {
                    print(&quot;ConnectionState waiting&quot;);
                    return CustomCircularProgressIndicator();
                  }
  </code></pre>
  <p>Getting these messages:</p>
  <pre><code>I/flutter (22472): Retrieve Lost Data 2021-09-08 18:56:32.045733
  I/flutter (22472): Retrieve Lost Data 2021-09-08 18:56:32.118169
  I/flutter (22472): ConnectionState waiting 2021-09-08 18:56:32.241322
  I/flutter (22472): ConnectionState waiting 2021-09-08 18:56:32.332024
  I/flutter (22472): Retrieve Lost Data 2021-09-08 18:56:36.267506
  I/flutter (22472): ConnectionState waiting 2021-09-08 18:56:36.342659
  </code></pre>
  <p>Any idea how to prevent this cycle?</p>
  <p>(If I remove the FutureBuilder the cycle stops and have no problem, the stream is not changing...)</p>