firebase/flutterfire

Introduce enablePersistenceForWeb() to avoid deprecated method on web

Open

#13,290 创建于 2024年9月8日

在 GitHub 查看
 (3 评论) (1 反应) (0 负责人)Dart (9,199 star) (4,097 fork)batch import
Needs Attentiongood first issueplatform: webplugin: cloud_firestoretype: documentation

描述

Description:
I'm using cloud_firestore: ^5.4.0 and Flutter stable channel 3.24.2, and I have encountered an issue where the enablePersistence() method is marked as deprecated, but it is still required for web-based Flutter apps.

Issue:

  • The method enablePersistence() is marked as deprecated in the latest version of cloud_firestore.
  • However, as per the official documentation, it is still necessary to use this method to enable offline persistence for web.
  • There is currently no alternative approach for enabling persistence on web platforms. Using a deprecated method can cause confusion, especially since Settings.persistenceEnabled only works for non-web platforms.

Suggestion:

Ideally, web should follow the same persistence system as the rest of the platforms. But until that is feasible, a dedicated method like enablePersistenceForWeb() should be introduced to:

  1. Avoid using a deprecated method on web.
  2. Clearly differentiate web-specific persistence behavior.
  3. Prevent confusion and the need for developers to use // ignore: deprecated_member_use, which would hide the moment when web persistence truly becomes deprecated with this method.

Using // ignore: deprecated_member_use forces web developers to ignore the deprecation warning, making it difficult to know when the proper system for web has been implemented and when the method should no longer be used.

Steps to Reproduce:

  1. Use cloud_firestore: ^5.4.0 in a Flutter app targeting web.
  2. Attempt to implement offline persistence using Settings.persistenceEnabled.
  3. Observe that the method is deprecated but still required for web, leading to confusion.

Expected Behavior:

  • Either a dedicated method (enablePersistenceForWeb()) should be introduced, or the deprecation should be removed for web-based usage.
  • Web developers should have a clear and non-deprecated method to enable offline persistence until web can share the same persistence system as other platforms.

This approach would enhance clarity, prevent misuse of deprecated methods, and help web developers anticipate the proper transition when the persistence system is unified across platforms.

贡献者指南

Introduce enablePersistenceForWeb() to avoid deprecated method on web · firebase/flutterfire#13290 | Good First Issue