feat(umgebung): Server-Umgebung im Login-Screen waehlbar (Produktion/Test)
- Umgebungen (Name, API-URL, Keycloak-Issuer) kommen aus assets/hl_server_config.json statt hartcodiertem BackendConfig.prod; Testumgebung 192.168.1.9:3001 ist dort hinterlegt - AppBloc laedt die Config, aktiviert die gespeicherte Wahl (Fallback Default) und registriert das Networking; Wechsel persistiert per SharedPreferences und registriert neu - Bloc-Baum ist pro Umgebung gekeyt: beim Wechsel entstehen alle Blocs mit dem neuen API-Client neu - Login-Screen: Zahnrad oben rechts oeffnet Einstellungen mit Umgebungs- Cards (Name + IP:Port); Hinweis auf aktive Umgebung unter dem Button - Fahrzeugauswahl pro Umgebung getrennt (eigene DB = eigene Car-IDs) - Tests fuer Config-Parsing, Auswahl-Fallback, Card-Wechsel, Re-Registrierung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
35
lib/data/network/environment_repository.dart
Normal file
35
lib/data/network/environment_repository.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'backend_environment.dart';
|
||||
|
||||
/// Lädt die Umgebungsliste aus der Asset-Config und persistiert, welche
|
||||
/// Umgebung der Nutzer gewählt hat.
|
||||
///
|
||||
/// Bewusst wird nur die **Auswahl** gespeichert, nicht die Liste selbst:
|
||||
/// So wirkt eine geänderte Config (neue IP, neue Umgebung) mit dem
|
||||
/// nächsten App-Update, ohne dass veraltete Kopien im Gerät hängen.
|
||||
class EnvironmentRepository {
|
||||
static const _selectedKey = 'selected_backend_environment';
|
||||
|
||||
Future<ServerCatalog> loadCatalog(String assetPath) async {
|
||||
final raw = await rootBundle.loadString(assetPath);
|
||||
final json = jsonDecode(raw);
|
||||
if (json is! Map<String, dynamic>) {
|
||||
throw const FormatException('Config ist kein JSON-Objekt.');
|
||||
}
|
||||
return ServerCatalog.fromJson(json);
|
||||
}
|
||||
|
||||
Future<String?> loadSelectedId() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString(_selectedKey);
|
||||
}
|
||||
|
||||
Future<void> saveSelectedId(String id) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_selectedKey, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user