reclaim/app/lib/main.dart
flemming-it 51beb332c4 feat(ui): ModeBanner replaces DemoBanner + no silent mock-fallback
Two related fixes so the app never silently presents itself as
a demo when it is in fact running against a real hub:

  - The orange 'Demo-Daten · KEINE Rechtsberatung' banner was
    hard-coded into every data screen, regardless of whether
    the active repository was the in-memory MockRepository or
    the live HubRepository. Replaced with ModeBanner, which
    picks one of three voices by repository.mode:

      demo      orange T4 — 'Demo-Daten · KEINE Rechtsberatung'
      hub-live  petrol     — 'Live aus Hub · <endpoint>'
      hub-down  warm-warn  — 'Hub nicht erreichbar — leere Liste'

  - main.dart's _pickRepository used to fall back to
    MockRepository whenever HubRepository.connect() came back
    unhealthy. That silently downgraded a live deployment to
    demo data, which is exactly what the user is trying to avoid.
    Removed: when useHub=true, the HubRepository is returned
    regardless. Its list() returns [] on hub-down, and the
    'hub-down' banner explains why the screens are empty.
    Mock data only shows when the user explicitly turns useHub
    off in the Hub-Reiter.

Also: legend arrow icons now point in the actual axis direction
(→ for Schaden, ↑ for Nutzen) instead of the bidirectional ↔/↕,
which suggested the axes ran both ways. Mini-chips and the
expanded legend rows are consistent.

Signed-off-by: flemming-it <sf@flemming.it>
2026-06-18 15:57:50 +02:00

60 lines
2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'data/hub_endpoint.dart';
import 'data/hub_repository.dart';
import 'data/repository.dart';
import 'pages/landing_page.dart';
import 'theme/reclaim_theme.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final settings = await HubSettings.load();
final repository = await _pickRepository(settings);
runApp(ReclaimApp(repository: repository, settings: settings));
}
/// Decide which repository to start with.
///
/// useHub=false → MockRepository, explicit opt-in to
/// demo data via the Hub-Reiter.
/// useHub=true → HubRepository regardless of probe
/// outcome. When unhealthy the
/// repository's list() returns [] and
/// the ModeBanner shows 'hub-down' —
/// no silent mock fallback that would
/// quietly demote the app to demo
/// mode.
Future<EvaluationRepository> _pickRepository(HubSettings settings) async {
if (!settings.useHub) return const MockRepository();
return HubRepository.connect(settings);
}
class ReclaimApp extends StatelessWidget {
const ReclaimApp({
super.key,
this.repository = const MockRepository(),
this.settings,
});
final EvaluationRepository repository;
final HubSettings? settings;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Recl∆Im',
debugShowCheckedModeBanner: false,
theme: ReclaimTheme.light(),
darkTheme: ReclaimTheme.dark(),
themeMode: ThemeMode.dark,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('de'), Locale('en')],
home: LandingPage(repository: repository),
);
}
}