Skip to content

Realtime Database connection is lost when app is disconnected from WiFi and reconnected back again #6507

Open
@ablbol

Description

[REQUIRED] Environment info

12.8.0

firebase-tools:

macOs

Platform:

[REQUIRED] Test case

I have a Flutter app that is running on a real Android device with the Firebase emulator. I followed documentation to detect user presence. Here is the code from the docs:

final connectedRef = FirebaseDatabase.instance.ref(".info/connected");
connectedRef.onValue.listen((event) {
  final connected = event.snapshot.value as bool? ?? false;
  if (connected) {
    debugPrint("Connected.");
  } else {
    debugPrint("Not connected.");
  }
});

The problem starts when I disconnect the app from WiFi and then reconnect. I noticed that I lost the connection to the Realtime Database even though I was connected to WiFi. I also noticed that since I no longer have the Realtime Database connection, the document I am interested in has the right data in the app memory but not in the Realtime Database emulator.

This is how I am listening to the document that I am interested in:

    FirebaseDatabase.instance.ref('users/$uid').onValue.listen((event) {
      debugPrint('data: ${event.snapshot.value}');
    });

[REQUIRED] Steps to reproduce

See above

[REQUIRED] Expected behavior

I expect the Realtime Database connection to come back after reconnecting to WiFi.

I also noticed that when I use the following command, the app crashes even though the command is executed once.

FirebaseDatabase.instance.setPersistenceEnabled(true);

[REQUIRED] Actual behavior

See above

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions