Skip to content

[cloud_firestore] Null in stream on no network, unable to detect data absence or failure #17317

Open
@EArminjon

Description

@EArminjon

What feature would you like to see?

I want to report an issue with Firebase’s stream. When the device is offline (in airplane mode), the stream provides a null value, making it difficult to distinguish between the following scenarios:

  • The user has no subscriptions.
  • The user has maybe some subscriptions but is currently offline.

This causes an issue where, as a developer, I end up caching the null value when the stream returns null due to the lack of network connection. As a result, users appear to have no subscriptions even though they might actually have them, just offline.

It would be helpful if Firebase could provide a clearer way to handle this, so we can properly differentiate these scenarios and manage caching accordingly.

In the following example handleError is not called on network issue.

  @override
  Stream<List<SubscriptionEntity>> listenUserSubscriptions(String userId) {
    final DocumentReference<Map<String, dynamic>> ref = firestore
        .collection(_usersTable)
        .doc(userId)
        .collection(_purchaseTable)
        .doc(userId);
    return ref
        .snapshots()
        .map((DocumentSnapshot<Map<String, dynamic>> snapshot) {
          return SubscriptionModel.fromJson(snapshot.data() ?? {}).toDomain;
        })
        .handleError((Object err) {
          print("Error: $err");
        });

Metadata

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