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:
Dennis Nemec
2026-09-25 15:07:40 +02:00
parent 6b934e4534
commit 200992262a
15 changed files with 307 additions and 87 deletions

View File

@ -10,6 +10,8 @@ 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.dart';
import 'package:hl_lieferservice/feature/feature_flags/feature_flags_repository.dart';
import 'package:hl_lieferservice/feature/settings/presentation/environment_settings_page.dart';
/// Liest die echte Asset-Config, speichert die Auswahl im Speicher.
@ -31,6 +33,14 @@ class _FakeRepository extends EnvironmentRepository {
Future<void> saveSelectedId(String id) async => selectedId = id;
}
/// Ohne Asset-Bundle: leere Schalter (alle Features auf ihrem Default).
class _NoFlags extends FeatureFlagsRepository {
const _NoFlags();
@override
Future<FeatureFlags> load() async => const FeatureFlags({});
}
void main() {
late _FakeRepository repo;
late List<BackendConfig> activated;
@ -39,15 +49,20 @@ void main() {
setUp(() {
repo = _FakeRepository(null);
activated = [];
bloc = AppBloc(repository: repo, activate: activated.add);
bloc = AppBloc(
repository: repo,
activate: activated.add,
featureFlagsRepository: const _NoFlags(),
);
});
tearDown(() => bloc.close());
test('ohne gespeicherte Wahl startet die Default-Umgebung', () async {
bloc.add(AppLoadConfig(path: 'hl_server_config.json'));
final state = await bloc.stream.firstWhere((s) => s is AppConfigLoaded)
as AppConfigLoaded;
final state =
await bloc.stream.firstWhere((s) => s is AppConfigLoaded)
as AppConfigLoaded;
expect(state.active.id, 'production');
expect(activated.single.apiBaseUrl, 'http://192.168.1.9:3000');
@ -56,14 +71,16 @@ void main() {
test('gespeicherte, aber unbekannte Umgebung fällt auf Default', () async {
repo.selectedId = 'gibt-es-nicht';
bloc.add(AppLoadConfig(path: 'hl_server_config.json'));
final state = await bloc.stream.firstWhere((s) => s is AppConfigLoaded)
as AppConfigLoaded;
final state =
await bloc.stream.firstWhere((s) => s is AppConfigLoaded)
as AppConfigLoaded;
expect(state.active.id, 'production');
});
testWidgets('Card antippen wechselt Umgebung, speichert und schließt',
(tester) async {
testWidgets('Card antippen wechselt Umgebung, speichert und schließt', (
tester,
) async {
await tester.runAsync(() async {
bloc.add(AppLoadConfig(path: 'hl_server_config.json'));
await bloc.stream.firstWhere((s) => s is AppConfigLoaded);
@ -74,16 +91,18 @@ void main() {
value: bloc,
child: MaterialApp(
home: Builder(
builder: (context) => Scaffold(
body: TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const EnvironmentSettingsPage(),
builder:
(context) => Scaffold(
body: TextButton(
onPressed:
() => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const EnvironmentSettingsPage(),
),
),
child: const Text('open'),
),
),
child: const Text('open'),
),
),
),
),
),