feat(flags): Feature-Flags aus Config-Datei; Gutschriften-Abschnitt abschaltbar
- Schalter stehen in assets/feature_flags.json (Key -> enabled + Beschreibung) statt als Konstanten im Code - Enum Feature buendelt die stabilen Keys; FeatureFlags liest die Datei, ignoriert unbekannte Keys und nutzt fuer fehlende den Default aus dem Enum - Laden beim App-Start im AppBloc, bereitgestellt per RepositoryProvider; FeatureGate blendet Bereiche bei inaktivem Feature komplett aus - articles.credit_section = false: Abschnitt "Gutschriften" im Artikel-Step ist ausgeblendet - Bisheriges Stepper-Flag migriert (articles.credit_amount_stepper); die fuenf ungenutzten statischen Flags mit veralteten Kommentaren entfernt - Tests: Asset enthaelt alle Keys, Parsing, Defaults, FeatureGate Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -5,6 +5,7 @@ import 'package:hl_lieferservice/bloc/app_states.dart';
|
||||
import 'package:hl_lieferservice/data/network/backend_config.dart';
|
||||
import 'package:hl_lieferservice/data/network/backend_environment.dart';
|
||||
import 'package:hl_lieferservice/data/network/environment_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/feature_flags/feature_flags_repository.dart';
|
||||
|
||||
/// Aktiviert das Networking für eine Umgebung (Registrierung im Locator).
|
||||
typedef EnvironmentActivator = void Function(BackendConfig config);
|
||||
@ -13,14 +14,18 @@ typedef EnvironmentActivator = void Function(BackendConfig config);
|
||||
///
|
||||
/// Liest die Server-Umgebungen aus `assets/hl_server_config.json`,
|
||||
/// bestimmt die aktive Umgebung (gespeicherte Wahl, sonst Default) und
|
||||
/// registriert dafür das Networking. Ein Umgebungswechsel läuft über
|
||||
/// denselben Weg; die UI baut ihren Bloc-Baum pro Umgebung neu auf.
|
||||
/// registriert dafür das Networking. Außerdem lädt er die Feature-Schalter
|
||||
/// aus `assets/feature_flags.json`. Ein Umgebungswechsel läuft über denselben
|
||||
/// Weg; die UI baut ihren Bloc-Baum pro Umgebung neu auf.
|
||||
class AppBloc extends Bloc<AppEvents, AppState> {
|
||||
AppBloc({
|
||||
required EnvironmentRepository repository,
|
||||
required EnvironmentActivator activate,
|
||||
FeatureFlagsRepository featureFlagsRepository =
|
||||
const FeatureFlagsRepository(),
|
||||
}) : _repository = repository,
|
||||
_activate = activate,
|
||||
_featureFlagsRepository = featureFlagsRepository,
|
||||
super(const AppInitial()) {
|
||||
on<AppLoadConfig>(_onLoad);
|
||||
on<AppSwitchEnvironment>(_onSwitch);
|
||||
@ -28,20 +33,26 @@ class AppBloc extends Bloc<AppEvents, AppState> {
|
||||
|
||||
final EnvironmentRepository _repository;
|
||||
final EnvironmentActivator _activate;
|
||||
final FeatureFlagsRepository _featureFlagsRepository;
|
||||
|
||||
Future<void> _onLoad(AppLoadConfig event, Emitter<AppState> emit) async {
|
||||
emit(const AppConfigLoading());
|
||||
try {
|
||||
final catalog = await _repository.loadCatalog('assets/${event.path}');
|
||||
final featureFlags = await _featureFlagsRepository.load();
|
||||
final storedId = await _repository.loadSelectedId();
|
||||
// Unbekannte ID (Umgebung aus der Config entfernt) → Default.
|
||||
final active = catalog.byId(storedId) ?? catalog.defaultEnvironment;
|
||||
_activate(catalog.configFor(active));
|
||||
emit(AppConfigLoaded(catalog: catalog, active: active));
|
||||
emit(AppConfigLoaded(
|
||||
catalog: catalog,
|
||||
active: active,
|
||||
featureFlags: featureFlags,
|
||||
));
|
||||
} catch (e, st) {
|
||||
debugPrint('AppBloc: Server-Config nicht ladbar: $e\n$st');
|
||||
debugPrint('AppBloc: Konfiguration nicht ladbar: $e\n$st');
|
||||
emit(AppConfigLoadingFailed(
|
||||
message: 'Server-Konfiguration konnte nicht geladen werden.\n$e',
|
||||
message: 'Konfiguration konnte nicht geladen werden.\n$e',
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -59,6 +70,10 @@ class AppBloc extends Bloc<AppEvents, AppState> {
|
||||
|
||||
await _repository.saveSelectedId(next.id);
|
||||
_activate(current.catalog.configFor(next));
|
||||
emit(AppConfigLoaded(catalog: current.catalog, active: next));
|
||||
emit(AppConfigLoaded(
|
||||
catalog: current.catalog,
|
||||
active: next,
|
||||
featureFlags: current.featureFlags,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user