title: Using Offline Persistence in Firestore in a Flutter App
body: <p>I'm developing a app that uses Firebase's Firestore to send data to the web. One of the functions of the app is being able to save data in the device while being offline and send it to Firestore when internet connection is restored.
  I activated offline persistence but it dosen't work.</p>
  
  <p><strong>DEBUG CONSOLE:</strong></p>
  
  <pre><code>W/OkHttpClientTransport(28536): Failed closing connection
  W/OkHttpClientTransport(28536): javax.net.ssl.SSLException: Write error: ssl=0x7f7acfc408: I/O error during system call, Broken pipe
  W/OkHttpClientTransport(28536):     at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_write(Native Method)
  W/OkHttpClientTransport(28536):     at com.google.android.gms.org.conscrypt.NativeSsl.write(:com.google.android.gms@14798020@14.7.98 (040406-222931072):4)
  </code></pre>
  
  <p>How can I activate offline persistence and sync with Firestore when internet is restored?</p>
  
  <p><strong>MY CODE:</strong></p>
  
  <pre><code>Future&lt;Null&gt; sendFirebaseData(var selectedModel) async {
  
      Firestore.instance.enablePersistence(true);
      var certID = await getIDCertificado();
  
      var dateTime = new DateTime.now();
      var nowHour = new DateFormat('kk:mm:ss').format(dateTime);
  
        Map&lt;String, dynamic&gt; dataHeader = {
          'ID':                certID,
          };
  
        Map&lt;String, dynamic&gt; finalDataMap = {}..addAll(dataGeneral)
                                            ..addAll(dataInstrumento)..addAll(dataPadrao)
                                            ..addAll(dataAdicional)..addAll(dataHeader);
  
        await Firestore.instance.collection('certificados').document((certID.toString()))
            .setData(finalDataMap);}
  </code></pre>