diff --git a/lib/data/remote_config_service.dart b/lib/data/remote_config_service.dart index 9fc83fc..8243dd2 100644 --- a/lib/data/remote_config_service.dart +++ b/lib/data/remote_config_service.dart @@ -24,7 +24,6 @@ class RemoteConfigService { await remoteConfig.setDefaults(featuresDefaultValues.map((key, value) => MapEntry(key.name, value))); await remoteConfig.activate(); await remoteConfig.ensureInitialized(); - unawaited(remoteConfig.fetch()); log('Firebase remote config initialized successfully'); } on FirebaseException catch (e) { @@ -34,6 +33,12 @@ class RemoteConfigService { } } + Future fetchConfig() async { + // https://github.com/firebase/flutterfire/issues/6196#issuecomment-927751667 + await Future.delayed(const Duration(seconds: 1)); + await FirebaseRemoteConfig.instance.fetch(); + } + dynamic getValue(Feature feature) => FirebaseRemoteConfig.instance.getValue(feature.name).toValue(feature); Map getAll() { diff --git a/lib/providers/remote_config_provider.dart b/lib/providers/remote_config_provider.dart index 9736e1d..a00b385 100644 --- a/lib/providers/remote_config_provider.dart +++ b/lib/providers/remote_config_provider.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/feature.dart'; @@ -25,7 +26,11 @@ class RemoteConfigProviderState extends State { @override void initState() { super.initState(); - _updatesSubscription = widget.remoteConfigService.onConfigUpdated().listen(_updateFeatures); + widget.remoteConfigService.fetchConfig(); + _updatesSubscription = widget.remoteConfigService.onConfigUpdated().listen( + _updateFeatures, + onError: (e) => log(e.toString()), + ); } @override diff --git a/test/providers/remote_config_provider_test.dart b/test/providers/remote_config_provider_test.dart index aa6815d..a215cbe 100644 --- a/test/providers/remote_config_provider_test.dart +++ b/test/providers/remote_config_provider_test.dart @@ -18,6 +18,7 @@ void main() { }); setUp(() { + when(() => mockRemoteConfigService.fetchConfig()).thenAnswer((_) async {}); when(() => mockRemoteConfigService.getValue(Feature.unlockProFeaturesText)).thenReturn(false); when(() => mockRemoteConfigService.getAll()).thenReturn({Feature.unlockProFeaturesText: false}); });