init method

Future<void> init()

Initializes the repository by loading local defaults into Remote Config and warming up the flag cache.

Implementation

Future<void> init() async {
  // Initialize Remote Config with local defaults
  try {
    final localJson = await _service.loadLocalJson();
    await firebaseService.init(defaults: {'feature_flags': localJson});

    // Listen for remote updates
    firebaseService.onConfigUpdated.listen((_) {
      log(
        'Remote Config updated, invalidating feature flag cache',
        name: 'FeatureFlagRepository',
      );
      _defaultsCache = null;
      _flagsCache = null;
      _updateController.add(null);
    });
  } catch (e) {
    log(
      'Failed to initialize Remote Config defaults: $e',
      name: 'FeatureFlagRepository',
    );
  }

  await getAllFlags();
  log('FeatureFlagRepository initialized', name: 'FeatureFlagRepository');
}