flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_database]: Firebase Database not auto synced after regain connection

Open haizadvnet opened this issue 8 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Which plugins are affected?

Database

Which platforms are affected?

Android

Description

When using Firebase Realtime Database, it is expected that any data changes made while the device is offline will automatically sync to the Firebase server once the connection is reestablished, as what described on https://firebase.google.com/docs/database/flutter/offline-capabilities#section-offline-behavior. However, an issue has been observed where data inserted while offline does not sync immediately upon regaining the internet connection.

Reproducing the issue

  1. Go offline and start inserting data to firebase.
  2. Switch on internet.
  3. The data does not synced to the Firebase server.
  4. Start inserting data B to firebase while online.
  5. Only then data A and data B synced to the Firebase server.

Minimal code as below:


Future<FbModel?> writeData() async {
     
      FirebaseDatabase database;
      database = FirebaseDatabase.instance;
      database.setPersistenceEnabled(true);
      
      final databaseRef = database.ref("notifications");
       ....
      
      databaseRef.child(path/subPath).set(
      {
         'date':DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
         'sync':ServerValue.timestamp
      });

}

Firebase Core version

2.17.0

Flutter Version

3.22.1

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet

Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

There are no firebase_database listeners attached to the app; the Firebase Database is used solely for sending data.

haizadvnet avatar Jun 06 '24 01:06 haizadvnet