1

I'm using Firebase Realtime Database in a Flutter app and listening for updates using the onValue stream. Here's the code I’m using:

_plansSubscription = _plansRef
    .orderByChild('userId')
    .equalTo(userId)
    .onValue
    .listen((DatabaseEvent event) {
      // Handle data
    });

This works correctly on Android, where the listener is only triggered when actual changes happen in the data.

However, on iOS, the same listener is being called multiple times, even when no changes are made to the data. This is causing unnecessary processing and inconsistent app behavior.

I’m using this logic inside a Provider, not directly in a widget, and the listener is only set up once during provider initialization.

What I’ve verified:

  1. Firebase is initialized properly in main() using:

    await Firebase.initializeApp();

  2. The GoogleService-Info.plist file is correctly added to the Xcode project.

  3. iOS Info.plist has the required network permissions:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Firebase rules in the console allow public access for testing:

{
  "rules": {
    ".read": "true",
    ".write": "true"
  }
}

The listener is not duplicated. It's disposed of properly in the provider:

Why does the onValue listener in Firebase Realtime Database get triggered repeatedly on iOS, even when there are no actual data changes? How can I prevent this or handle it more efficiently?

2
  • you can store the snapshot to a variable then compare it to it before processing, if newSnapshot != lastSnapshot then you process. Commented Aug 5 at 5:16
  • If the behavior is different between platforms, this sounds like it may be a bug. It might be worth it to report this on github.com/firebase/flutterfire Commented Aug 5 at 13:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.