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.73k stars 3.98k forks source link

🐛 firebase_database FirebaseDatabase.instance.onValue.listen does not call listener when disconnecting from Wifi then reconnecting back again. #11823

Closed ablbol closed 1 year ago

ablbol commented 1 year ago

Bug report

Describe the bug The following code, which I got from docs, is updated every time the Firebase Realtime Database client's connection state changes

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.");
  }
});

When the app is disconnected from WiFi then is connected back again, then the listener, in the code, is no longer called.

Steps to reproduce

The code above show how to reproduce the problem

Expected behavior

When the app is connected back to the WiFi, I expected the listener above to be called with connected == true. However, the listener is not called after connecting back to WiFi.

Sample project

Code is shown above


Additional context

None

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.9, on macOS 13.5.2 22G91 darwin-x64, locale en-AE) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [!] Xcode - develop for iOS and macOS (Xcode 15.0.1) ✗ Unable to get list of installed Simulator runtimes. [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.83.1) [✓] Connected device (4 available) [✓] Network resources ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 3.1.5 Flutter SDK 3.13.9 oolfa 1.2.12+38 dependencies: - android_id 0.3.6 [flutter] - audio_waveforms 1.0.4 [flutter] - badges 3.1.2 [flutter] - cached_network_image 3.3.0 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image] - carousel_slider 4.2.1 [flutter] - cloud_firestore 4.9.3 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 4.4.2 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - connectivity_plus 5.0.1 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm] - device_info_plus 9.1.0 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32 win32_registry] - dotted_border 2.1.0 [flutter path_drawing] - firebase_analytics 10.5.1 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_app_check 0.2.0+1 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.10.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.17.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.3.7 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_database 10.2.7 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter] - firebase_messaging 14.6.9 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_remote_config 4.2.7 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - firebase_storage 11.2.8 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - firebase_ui_firestore 1.5.12 [cloud_firestore firebase_ui_localizations flutter] - flash 3.0.5+1 [flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_dotenv 5.1.0 [flutter] - flutter_facebook_auth 6.0.2 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web facebook_auth_desktop] - flutter_hooks 0.20.3 [flutter] - flutter_image_compress 2.0.4 [flutter flutter_image_compress_platform_interface flutter_image_compress_common flutter_image_compress_web] - flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_local_notifications 16.1.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math web] - flutter_slidable 3.0.0 [flutter] - flutter_svg 2.0.7 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - geocoding 2.1.1 [flutter geocoding_platform_interface geocoding_android geocoding_ios] - geolocator 10.1.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - go_router 11.1.4 [collection flutter flutter_web_plugins logging meta] - google_sign_in 6.1.5 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - hooks_riverpod 2.4.3 [collection flutter flutter_hooks flutter_riverpod riverpod state_notifier] - http 1.1.0 [async http_parser meta] - image_cropper 5.0.0 [flutter image_cropper_platform_interface image_cropper_for_web] - image_picker 0.8.9 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows] - intl 0.18.1 [clock meta path] - just_audio 0.9.35 [just_audio_platform_interface just_audio_web audio_session rxdart path path_provider async uuid crypto meta flutter] - mask_text_input_formatter 2.5.0 [flutter] - material_design_icons_flutter 6.0.7296 [flutter] - open_mail_app 0.4.5 [platform url_launcher flutter] - package_info_plus 4.2.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - path 1.8.3 - path_provider 2.1.1 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - permission_handler 11.0.1 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - photo_view 0.14.0 [flutter] - purchases_flutter 4.13.0 [flutter freezed_annotation json_annotation] - rate_my_app 2.0.0 [shared_preferences flutter_rating_bar flutter] - rxdart 0.27.7 - scrollable_positioned_list 0.3.8 [flutter collection] - share_plus 7.2.0 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32] - shared_preferences 2.2.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shimmer 3.0.0 [flutter] - showcaseview 2.0.3 [flutter] - stack_trace 1.11.0 [path] - store_redirect 2.0.1 [flutter] - swipe_to 1.0.2 [flutter] - timeago 3.5.0 [intl] - url_launcher 6.1.14 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - uuid 3.0.7 [crypto] - webview_flutter 4.4.1 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] dev dependencies: - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - mocktail 1.0.1 [collection matcher test_api] - very_good_analysis 5.1.0 transitive dependencies: - _flutterfire_internals 1.3.7 [collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.3.6 [crypto path pointycastle] - args 2.3.2 - async 2.11.0 [collection meta] - audio_session 0.1.14 [flutter flutter_web_plugins rxdart meta] - boolean_selector 2.1.1 [source_span string_scanner] - cached_network_image_platform_interface 3.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.1.0 [cached_network_image_platform_interface flutter flutter_cache_manager] - characters 1.3.0 - checked_yaml 2.0.2 [json_annotation source_span yaml] - cli_util 0.4.0 [meta path] - clock 1.1.1 - cloud_firestore_platform_interface 5.16.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.7.2 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.5.2 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.6.2 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.17.2 - connectivity_plus_platform_interface 1.2.4 [flutter meta plugin_platform_interface] - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.2 [typed_data] - dbus 0.7.8 [args ffi meta xml] - device_info_plus_platform_interface 7.0.0 [flutter meta plugin_platform_interface] - facebook_auth_desktop 1.0.1 [flutter http flutter_secure_storage flutter_facebook_auth_platform_interface] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - file_selector_linux 0.9.2+1 [cross_file file_selector_platform_interface flutter] - file_selector_macos 0.9.3+3 [cross_file file_selector_platform_interface flutter] - file_selector_platform_interface 2.6.1 [cross_file flutter http plugin_platform_interface] - file_selector_windows 0.9.3+1 [cross_file file_selector_platform_interface flutter] - firebase_analytics_platform_interface 3.7.1 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.5+1 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_app_check_platform_interface 0.1.0+1 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_app_check_web 0.1.0+1 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.19.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.8.2 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.8.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.6.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_database_platform_interface 0.2.5+7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_database_web 0.2.3+7 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins js] - firebase_messaging_platform_interface 4.5.8 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.8 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_remote_config_platform_interface 1.4.7 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.4.7 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - firebase_storage_platform_interface 4.4.7 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.6.8 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - firebase_ui_localizations 1.7.0 [flutter flutter_localizations path] - flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid] - flutter_facebook_auth_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_facebook_auth_web 5.0.0 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface] - flutter_image_compress_common 1.0.2 [flutter flutter_image_compress_platform_interface] - flutter_image_compress_platform_interface 1.0.2 [flutter plugin_platform_interface cross_file] - flutter_image_compress_web 0.1.3+1 [flutter flutter_web_plugins flutter_image_compress_platform_interface js] - flutter_local_notifications_linux 4.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 7.0.0+1 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.7 [flutter] - flutter_rating_bar 4.0.1 [flutter] - flutter_riverpod 2.4.3 [collection flutter meta riverpod state_notifier] - flutter_secure_storage 9.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - flutter_secure_storage_linux 1.1.3 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 3.0.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.1 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 3.0.0 [ffi flutter flutter_secure_storage_platform_interface path path_provider win32] - freezed_annotation 2.2.0 [collection json_annotation meta] - geocoding_android 2.1.0 [flutter geocoding_platform_interface] - geocoding_ios 2.1.0 [flutter geocoding_platform_interface] - geocoding_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - geolocator_android 4.3.1 [flutter geolocator_platform_interface uuid] - geolocator_apple 2.3.2 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.1.1 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.2.0 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.2.1 [flutter geolocator_platform_interface] - google_identity_services_web 0.2.1 [js meta] - google_sign_in_android 6.1.5 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.5.1 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.4.0 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.12.0+5 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.0.15 [archive meta xml] - image_cropper_for_web 3.0.0 [flutter flutter_web_plugins image_cropper_platform_interface js] - image_cropper_platform_interface 5.0.0 [flutter plugin_platform_interface http] - image_picker_android 0.8.5+5 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 2.1.10 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_ios 0.8.6+6 [flutter image_picker_platform_interface] - image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_macos 0.2.1+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_platform_interface 2.9.1 [cross_file flutter http plugin_platform_interface] - image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface] - js 0.6.7 [meta] - json_annotation 4.8.0 [meta] - just_audio_platform_interface 4.2.1 [flutter plugin_platform_interface] - just_audio_web 0.4.8 [just_audio_platform_interface flutter flutter_web_plugins] - logging 1.1.1 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.9.1 - mime 1.0.4 - nm 0.5.0 [dbus] - octo_image 2.0.0 [flutter] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path_drawing 1.0.1 [vector_math meta path_parsing flutter] - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.2.0 [flutter path_provider_platform_interface] - path_provider_foundation 2.3.1 [flutter path_provider_platform_interface] - path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.1 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32] - permission_handler_android 11.1.0 [flutter permission_handler_platform_interface] - permission_handler_apple 9.1.4 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.12.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.3 [flutter permission_handler_platform_interface] - petitparser 5.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.6 [meta] - pointycastle 3.6.2 [collection convert js] - process 4.2.4 [file path platform] - quiver 3.2.1 [matcher] - riverpod 2.4.3 [meta stack_trace state_notifier] - share_plus_platform_interface 3.3.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - shared_preferences_android 2.1.4 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.2.2 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.2.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.3.1 [flutter plugin_platform_interface] - shared_preferences_web 2.1.0 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.2.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sqflite 2.2.4+1 [flutter sqflite_common path] - sqflite_common 2.4.2+2 [synchronized path meta] - state_notifier 0.7.2+1 [meta] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - synchronized 3.0.1 - term_glyph 1.2.1 - test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - timezone 0.9.1 [path] - typed_data 1.3.1 [collection] - url_launcher_android 6.0.23 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.18 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.2 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.16 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.6 [flutter url_launcher_platform_interface] - vector_graphics 1.1.9 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.9 - vector_graphics_compiler 1.1.9 [args meta path_parsing xml vector_graphics_codec path] - vector_math 2.1.4 - web 0.1.4-beta - webview_flutter_android 3.12.0 [flutter webview_flutter_platform_interface] - webview_flutter_platform_interface 2.6.0 [flutter meta plugin_platform_interface] - webview_flutter_wkwebview 3.9.1 [flutter path webview_flutter_platform_interface] - win32 5.0.3 [ffi] - win32_registry 1.1.1 [ffi win32] - xdg_directories 0.2.0+3 [meta path process] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.1 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

Thanks for the report @ablbol

When the app is disconnected from WiFi then is connected back again, then the listener, in the code, is no longer called.

Any network related operation is most probably not a flutterfire issue, as the plugins are thin wrappers around native Firebase SDKs with which the data is sent to and fro using Dart. See similar reports for other frameworks: https://github.com/firebase/firebase-admin-python/issues/287

I suggest you to reach out to native Firebase SDK repo or firebase support for further course of action. I'll close this issue for now. If you disagree, write in comments and I'll reopen it.