Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_remote_config]: onConfigUpdated doesn't support multiple listeners #13495

Open
1 task done
Colman opened this issue Oct 11, 2024 · 2 comments · May be fixed by #13512
Open
1 task done

[firebase_remote_config]: onConfigUpdated doesn't support multiple listeners #13495

Colman opened this issue Oct 11, 2024 · 2 comments · May be fixed by #13512
Labels
Needs Attention This issue needs maintainer attention. platform: android Issues / PRs which are specifically for Android. plugin: remote_config type: bug Something isn't working

Comments

@Colman
Copy link

Colman commented Oct 11, 2024

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Remote Config

Which platforms are affected?

Android

Description

When adding multiple listeners to the onConfigUpdated stream, only the most recently added listener fires when there's an event

Reproducing the issue

The following will print "event2" but not "event1" when the config is updated:

import 'dart:async';

import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class Example extends ConsumerStatefulWidget {
  @override
  ConsumerState<Example> createState() => _ExampleState();
}

class _ExampleState extends ConsumerState<Example> {
  late StreamSubscription<RemoteConfigUpdate> _subscription1;
  late StreamSubscription<RemoteConfigUpdate> _subscription2;

  @override
  void initState() {
    super.initState();

    _subscription1 = FirebaseRemoteConfig.instance.onConfigUpdated.listen(
      (event) {
        print('event1');
      },
    );
    _subscription2 = FirebaseRemoteConfig.instance.onConfigUpdated.listen(
      (event) {
        print('event2');
      },
    );
  }

  @override
  void dispose() {
    _subscription1.cancel();
    _subscription2.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Firebase Core version

3.4.0

Flutter Version

3.22.2

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
- android_path_provider 0.3.0 [flutter]                                                                                                                                   
- android_time_picker 0.0.1 [flutter plugin_platform_interface]                                                                                                           
- async 2.11.0 [collection meta]                                                                                                                                          
- billing 1.0.0 [dio openapi_dart_common collection]                                                                                                                      
- branch 1.0.0 [dio openapi_dart_common collection]                                                                                                                       
- carousel_slider 4.2.1 [flutter]                                                                                                                                         
- city 1.0.0 [dio openapi_dart_common collection]                                                                                                                         
- collection 1.18.0                                                                                                                                                       
- crypto 3.0.3 [typed_data]                                                                                                                                               
- cupertino_icons 1.0.5                                                                                                                                                   
- customer 1.0.0 [dio openapi_dart_common collection]                                                                                                                     
- device_info_plus 9.0.3 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32 win32_registry]                                             
- firebase_analytics 11.3.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]                         
- firebase_app_installations 0.3.1+1 [firebase_app_installations_platform_interface firebase_app_installations_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 3.4.0 [firebase_core_platform_interface firebase_core_web flutter meta]                                                                                   
- firebase_crashlytics 4.1.0 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]                                 
- firebase_dynamic_links 6.0.5 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]          
- firebase_remote_config 5.1.0 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter]              
- fk_user_agent 2.1.0 [flutter]                                                                                                                                           
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]                                                                              
- flutter_inappwebview 6.0.0 [flutter flutter_inappwebview_platform_interface flutter_inappwebview_android flutter_inappwebview_ios flutter_inappwebview_macos flutter_inappwebview_web]
- flutter_layout_grid 2.0.5 [flutter collection meta quiver]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_polyline_points 2.0.0 [flutter http]
- flutter_riverpod 2.5.1 [collection flutter meta riverpod state_notifier]
- flutter_secure_storage 9.2.2 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta]
- flutter_widget_from_html_core 0.14.9 [csslib flutter html logging]
- fluttertoast 8.2.6 [flutter flutter_web_plugins web]
- generalapi 1.0.0 [dio openapi_dart_common collection]
- geocoding 2.1.0 [flutter geocoding_platform_interface geocoding_android geocoding_ios]
- geolocator 11.0.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- go_router 12.1.3 [collection flutter flutter_web_plugins logging meta]
- google_maps_flutter 2.7.1 [flutter google_maps_flutter_android google_maps_flutter_ios google_maps_flutter_platform_interface google_maps_flutter_web]
- html 0.15.4 [csslib source_span]
- http 1.1.0 [async http_parser meta]
- image_picker 1.0.2 [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.19.0 [clock meta path]
- json_annotation 4.8.1 [meta]
- json_serializable 6.7.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
- just_the_tooltip 0.0.12 [flutter]
- oauth2 2.0.2 [collection crypto http http_parser]
- open_filex 4.3.2 [flutter ffi]
- package_info_plus 4.1.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32]
- path 1.9.0
- path_provider 2.1.0 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- percent_indicator 4.2.3 [flutter]
- permission_handler 10.4.3 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- plan 1.0.0 [dio openapi_dart_common collection]
- promotion 1.0.0 [dio openapi_dart_common collection]
- rebatepass 1.0.0 [dio openapi_dart_common collection]
- rental 1.0.0 [dio openapi_dart_common collection]
- riverpod_annotation 2.3.5 [meta riverpod]
- scrollable_positioned_list 0.3.8 [flutter collection]
- shared_preferences 2.2.0 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- skeleton_text 3.0.1 [flutter]
- stack_trace 1.11.1 [path]
- station 1.0.0 [dio openapi_dart_common collection]
- timezone 0.9.2 [path]
- tuple 2.0.2
- url_launcher 6.2.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- vehicle 1.0.0 [dio openapi_dart_common collection]
- version 3.0.2
- zone 1.0.0 [dio openapi_dart_common collection]

dev dependencies:
- build_runner 2.4.7 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime packa
ge_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- firebase_core_platform_interface 5.3.0 [collection flutter flutter_test meta plugin_platform_interface]
- flutter_lints 2.0.2 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta s
ource_span stream_channel string_scanner term_glyph vm_service]
- integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service async boolean_selector characters clock collection fake_async file leak_tracker leak_tracker_flutter_testing leak_tracker_testing matcher material_color_u
tilities meta source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math webdriver]
- mockito 5.4.4 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api]
- path_provider_platform_interface 2.1.0 [flutter platform plugin_platform_interface]
- patrol 3.9.0 [equatable flutter flutter_test http json_annotation meta patrol_finders shelf test_api]
- plugin_platform_interface 2.1.8 [meta]
- riverpod_generator 2.4.0 [analyzer build build_config collection crypto meta path riverpod_analyzer_utils riverpod_annotation source_gen]
- riverpod_lint 2.3.10 [analyzer analyzer_plugin collection custom_lint_builder meta path riverpod riverpod_analyzer_utils source_span yaml]
- test 1.25.2 [analyzer async boolean_selector collection coverage http_multi_server io js matcher node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_chan
nel test_api test_core typed_data web_socket_channel webkit_inspection_protocol yaml]
- very_good_analysis 5.1.0
- yaml 3.1.2 [collection source_span string_scanner]

transitive dependencies:
- _fe_analyzer_shared 67.0.0 [meta]
- _flutterfire_internals 1.3.41 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 6.4.1 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- analyzer_plugin 0.11.3 [analyzer collection dart_style pub_semver yaml]
- args 2.5.0
- boolean_selector 2.1.1 [source_span string_scanner]
- build 2.4.1 [analyzer async convert crypto glob logging meta package_config path]
- build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 4.0.1 [built_collection built_value crypto http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.4.2 [analyzer async build collection convert crypto graphs logging package_config path pool pub_semver stream_transform yaml]
- build_runner_core 7.3.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta package_config path pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.9.2 [built_collection collection fixnum meta]
- characters 1.3.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- ci 0.1.0
- cli_util 0.4.1 [meta path]
- clock 1.1.1
- code_builder 4.10.0 [built_collection built_value collection matcher meta]
- convert 3.1.1 [typed_data]
- coverage 1.7.2 [args logging package_config path source_maps stack_trace vm_service]
- cross_file 0.3.4+1 [meta web]
- csslib 1.0.0 [source_span]
- custom_lint 0.6.4 [analyzer analyzer_plugin args async ci cli_util collection custom_lint_core freezed_annotation json_annotation meta package_config path pub_semver pubspec_parse rxdart uuid yaml]
- custom_lint_builder 0.6.4 [analyzer analyzer_plugin collection custom_lint custom_lint_core glob hotreloader meta package_config path pubspec_parse rxdart]
- custom_lint_core 0.6.3 [analyzer analyzer_plugin collection glob matcher meta package_config path pubspec_parse source_span yaml]
- dart_style 2.3.6 [analyzer args collection path pub_semver source_span]
- device_info_plus_platform_interface 7.0.1 [flutter meta plugin_platform_interface]
- dio 4.0.6 [http_parser path]
- equatable 2.0.5 [collection meta]
- fake_async 1.3.1 [clock collection]
- ffi 2.1.2
- file 7.0.0 [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 4.2.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.9+2 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- firebase_app_installations_platform_interface 0.1.4+41 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_installations_web 0.1.5+13 [_flutterfire_internals firebase_app_installations_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- firebase_core_web 2.17.5 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_crashlytics_platform_interface 3.6.41 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_dynamic_links_platform_interface 0.2.6+41 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_platform_interface 1.4.41 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_web 1.6.13 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins]
- fixnum 1.1.0
- flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver async boolean_selector characters clock collection leak_tracker leak_tracker_flutter_testing leak_tracker_testing matcher
 material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math]
- flutter_inappwebview_android 1.0.13 [flutter flutter_inappwebview_platform_interface]
- flutter_inappwebview_internal_annotations 1.1.1
- flutter_inappwebview_ios 1.0.13 [flutter flutter_inappwebview_platform_interface]
- flutter_inappwebview_macos 1.0.11 [flutter flutter_inappwebview_platform_interface]
- flutter_inappwebview_platform_interface 1.0.10 [flutter flutter_inappwebview_internal_annotations plugin_platform_interface]
- flutter_inappwebview_web 1.0.8 [flutter flutter_web_plugins js flutter_inappwebview_platform_interface]
- flutter_plugin_android_lifecycle 2.0.19 [flutter]
- flutter_secure_storage_linux 1.2.1 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_macos 3.1.2 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_platform_interface 1.1.2 [flutter plugin_platform_interface]
- flutter_secure_storage_web 1.2.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js]
- flutter_secure_storage_windows 3.1.2 [ffi flutter flutter_secure_storage_platform_interface path path_provider win32]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- freezed_annotation 2.4.1 [collection json_annotation meta]
- frontend_server_client 3.2.0 [async path]
- fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform]
- geocoding_android 2.1.2 [flutter geocoding_platform_interface]
- geocoding_ios 2.1.1 [flutter geocoding_platform_interface]
- geocoding_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- geolocator_android 4.5.4 [flutter geolocator_platform_interface meta uuid]
- geolocator_apple 2.3.7 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.1.0 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 3.0.0 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.2.3 [flutter geolocator_platform_interface]
- glob 2.1.2 [async collection file path string_scanner]
- google_maps 7.1.0 [js js_wrapping meta web]
- google_maps_flutter_android 2.12.0 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_ios 2.10.2 [flutter google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_platform_interface 2.8.0 [collection flutter plugin_platform_interface stream_transform]
- google_maps_flutter_web 0.5.8 [collection flutter flutter_web_plugins google_maps google_maps_flutter_platform_interface sanitize_html stream_transform web]
- graphs 2.3.1 [collection]
- hotreloader 4.2.0 [collection logging path stream_transform vm_service watcher]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.9+6 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 3.0.4 [flutter flutter_web_plugins image_picker_platform_interface mime web]
- image_picker_ios 0.8.9+2 [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.2 [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]
- io 1.0.4 [meta path string_scanner]
- js 0.6.7 [meta]
- js_wrapping 0.7.4 [js]
- leak_tracker 10.0.4 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 2.1.1
- logging 1.2.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.8.0 [collection]
- meta 1.12.0
- mime 1.0.5
- node_preamble 2.0.2
- openapi_dart_common 4.1.2 [dio]
- package_config 2.1.0 [path]
- package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- path_provider_android 2.2.4 [flutter path_provider_platform_interface]
- path_provider_foundation 2.3.2 [flutter path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32]
- patrol_finders 2.1.2 [flutter flutter_test meta]
- permission_handler_android 10.3.6 [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]
- platform 3.1.4
- pool 1.5.1 [async stack_trace]
- process 5.0.2 [file path platform]
- pub_semver 2.1.4 [collection meta]
- pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.2.1 [matcher]
- riverpod 2.5.1 [collection meta stack_trace state_notifier]
- riverpod_analyzer_utils 0.5.1 [analyzer collection crypto custom_lint_core freezed_annotation meta path source_span]
- rxdart 0.27.7
- sanitize_html 2.1.0 [html meta]
- shared_preferences_android 2.2.2 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.3.5 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.3.2 [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.3.0 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.3.2 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.1 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 3.0.2 [path shelf shelf_static]
- shelf_static 1.1.2 [convert http_parser mime path shelf]
- shelf_web_socket 1.0.4 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_gen 1.5.0 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.4 [analyzer collection source_gen]
- source_map_stack_trace 2.1.1 [path source_maps stack_trace]
- source_maps 0.10.12 [source_span]
- source_span 1.10.0 [collection path term_glyph]
- sprintf 7.0.0
- state_notifier 1.0.0 [meta]
- stream_channel 2.1.2 [async]
- stream_transform 2.1.0
- string_scanner 1.2.0 [source_span]
- sync_http 0.3.1
- term_glyph 1.2.1
- test_api 0.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- test_core 0.6.0 [analyzer args async boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel test_api vm_service y
aml]
- timing 1.0.1 [json_annotation]
- typed_data 1.3.2 [collection]
- url_launcher_android 6.2.2 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.2.5 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.1.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.1.0 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.3.0 [flutter plugin_platform_interface]
- url_launcher_web 2.3.1 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.1 [flutter url_launcher_platform_interface]
- uuid 4.4.0 [crypto sprintf meta fixnum]
- vector_math 2.1.4
- vm_service 14.2.1
- watcher 1.1.0 [async path]
- web 0.5.1
- web_socket_channel 2.4.5 [async crypto stream_channel web]
- webdriver 3.0.3 [matcher path stack_trace sync_http]
- webkit_inspection_protocol 1.2.1 [logging]
- win32 5.4.0 [ffi]
- win32_registry 1.1.3 [ffi win32]
- xdg_directories 1.0.4 [meta path]

Additional context and comments

No response

@Colman Colman added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Oct 11, 2024
@SelaseKay SelaseKay added plugin: remote_config platform: android Issues / PRs which are specifically for Android. labels Oct 14, 2024
@SelaseKay
Copy link
Contributor

Hi @Colman , thanks for the report. I'm able to reproduce this issue.

Steps to Reproduce

  1. Run the code below
  2. Update Remote config value in Firebase Console.
  3. Observe that only 'event2' is printed to console.
class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  StreamSubscription? subscription;
  RemoteConfigUpdate? update;
  late StreamSubscription<RemoteConfigUpdate> _subscription1;
  late StreamSubscription<RemoteConfigUpdate> _subscription2;

  @override
  void initState() {
    super.initState();
    _subscription1 = FirebaseRemoteConfig.instance.onConfigUpdated.listen(
      (event) {
        print('event1');
      },
    );
    _subscription2 = FirebaseRemoteConfig.instance.onConfigUpdated.listen(
      (event) {
        print('event2');
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Remote Config Example'),
      ),
      body: Column(
        children: [
          _ButtonAndText(
            defaultText: 'Not initialized',
            buttonText: 'Initialize',
            onPressed: () async {
              final FirebaseRemoteConfig remoteConfig =
                  FirebaseRemoteConfig.instance;
              await remoteConfig.setConfigSettings(
                RemoteConfigSettings(
                  fetchTimeout: const Duration(seconds: 10),
                  minimumFetchInterval: const Duration(hours: 1),
                ),
              );
              await remoteConfig.setDefaults(<String, dynamic>{
                'welcome': 'default welcome',
                'hello': 'default hello',
              });
              RemoteConfigValue(null, ValueSource.valueStatic);
              return 'Initialized';
            },
          ),
          _ButtonAndText(
            defaultText: 'No data',
            onPressed: () async {
              try {
                final FirebaseRemoteConfig remoteConfig =
                    FirebaseRemoteConfig.instance;
                // Using zero duration to force fetching from remote server.
                await remoteConfig.setConfigSettings(
                  RemoteConfigSettings(
                    fetchTimeout: const Duration(seconds: 10),
                    minimumFetchInterval: Duration.zero,
                  ),
                );
                await remoteConfig.fetchAndActivate();
                return 'Fetched: ${remoteConfig.getString('welcome')}';
              } on PlatformException catch (exception) {
                // Fetch exception.
                print(exception);
                return 'Exception: $exception';
              } catch (exception) {
                print(exception);
                return 'Unable to fetch remote config. Cached or default values will be '
                    'used';
              }
            },
            buttonText: 'Fetch Activate',
          ),
          _ButtonAndText(
            defaultText: update != null
                ? 'Updated keys: ${update?.updatedKeys}'
                : 'No data',
            onPressed: () async {
              try {
                final FirebaseRemoteConfig remoteConfig =
                    FirebaseRemoteConfig.instance;
                if (subscription != null) {
                  await subscription!.cancel();
                  setState(() {
                    subscription = null;
                  });
                  return 'Listening cancelled';
                }
                setState(() {
                  subscription =
                      remoteConfig.onConfigUpdated.listen((event) async {
                    // Make new values available to the app.
                    debugPrint('Remote config updated');
                    await remoteConfig.activate();

                    setState(() {
                      update = event;
                    });
                  });
                });

                return 'Listening, waiting for update...';
              } on PlatformException catch (exception) {
                // Fetch exception.
                print(exception);
                return 'Exception: $exception';
              } catch (exception) {
                print(exception);
                return 'Unable to listen to remote config. Cached or default values will be '
                    'used';
              }
            },
            buttonText: subscription != null ? 'Cancel' : 'Listen',
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    _subscription1.cancel();
    _subscription2.cancel();
    super.dispose();
  }
}

class _ButtonAndText extends StatefulWidget {
  const _ButtonAndText({
    Key? key,
    required this.defaultText,
    required this.onPressed,
    required this.buttonText,
  }) : super(key: key);

  final String defaultText;
  final String buttonText;
  final Future<String> Function() onPressed;

  @override
  State<_ButtonAndText> createState() => _ButtonAndTextState();
}

class _ButtonAndTextState extends State<_ButtonAndText> {
  String? _text;

  // Update text when widget is updated.
  @override
  void didUpdateWidget(covariant _ButtonAndText oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (widget.defaultText != oldWidget.defaultText) {
      setState(() {
        _text = widget.defaultText;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8),
      child: Row(
        children: [
          Text(_text ?? widget.defaultText),
          const Spacer(),
          ElevatedButton(
            onPressed: () async {
              final result = await widget.onPressed();
              setState(() {
                _text = result;
              });
            },
            child: Text(widget.buttonText),
          ),
        ],
      ),
    );
  }
}

@SelaseKay
Copy link
Contributor

Hi @Colman , as a workaround, you can do something like:

  final _onConfigUpdatedStream = FirebaseRemoteConfig.instance.onConfigUpdated;

  @override
  void initState() {
    super.initState();

    _onConfigUpdatedStream.listen(
      (event) {
        print('event1');
      },
    );

    _onConfigUpdatedStream.listen(
      (event) {
        print('event2');
      },
    );
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention This issue needs maintainer attention. platform: android Issues / PRs which are specifically for Android. plugin: remote_config type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants