firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.5k stars 3.92k forks source link

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

Open haizadvnet opened 3 weeks ago

haizadvnet commented 3 weeks ago

Is there an existing issue for this?

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
```yaml 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.

TarekkMA commented 2 weeks ago

Hey @haizadvnet, Thank you for reporting this issue, can you confirm if it would sync the item eventually after maybe a minute or so?

google-oss-bot commented 1 week ago

Hey @haizadvnet. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!