handleInitEvent method

Handle the FastAppSettingsBlocEventType.init event. This event is used to initialize the bloc. It will retrieve the settings from the data provider and dispatch a FastAppSettingsBlocEventType.initialized event.

Implementation

Stream<FastAppSettingsBlocState> handleInitEvent(
  FastAppSettingsBlocEventPayload? payload,
) async* {
  if (canInitialize) {
    _logger.debug('Initializing...');
    isInitializing = true;
    yield currentState.copyWith(isInitializing: true);

    final settings = await _retrievePersistedSettings();

    addEvent(FastAppSettingsBlocEvent.initialized(
      FastAppSettingsBlocEventPayload(
        theme: settings.theme ?? kFastSettingsThemeMap[ThemeMode.system],
        languageCode: payload?.languageCode ?? settings.languageCode,
        countryCode: payload?.countryCode ?? settings.countryCode,
        secondaryCurrencyCode: settings.secondaryCurrencyCode,
        primaryCurrencyCode: settings.primaryCurrencyCode,
        saveEntry: settings.saveEntry,
      ),
    ));
  }
}