Erweiterungen

This commit is contained in:
Sven committed 2026-02-25 10:49:49 +01:00
1 parent e9811da904
commit b94e8f252a
6 files changed
+45 -5

No files matched your search

+28
View File
@@ -55,6 +55,17 @@ class _MainPageState extends State<MainPage> with ConsumerMixin, ProducerMixin {
_refreshBadges(); _refreshBadges();
_initMessages(); _initMessages();
// Listener für Sprachänderungen
AppLocalizations().languageNotifier.addListener(_onLanguageChanged);
}
void _onLanguageChanged() {
if (mounted) {
setState(() {
// UI wird neu aufgebaut mit neuer Sprache
});
}
} }
@override @override
@@ -66,6 +77,9 @@ class _MainPageState extends State<MainPage> with ConsumerMixin, ProducerMixin {
unsubscribe(queueId: Constants.messageTopicJobDeleted); unsubscribe(queueId: Constants.messageTopicJobDeleted);
unsubscribe(queueId: Constants.messageTopicUpdateBadges); unsubscribe(queueId: Constants.messageTopicUpdateBadges);
unsubscribe(queueId: Constants.messageTopicBWVEnabled); unsubscribe(queueId: Constants.messageTopicBWVEnabled);
// Entferne Listener für Sprachänderungen
AppLocalizations().languageNotifier.removeListener(_onLanguageChanged);
super.dispose(); super.dispose();
} }
@@ -459,6 +473,17 @@ class _HeaderWidgetState extends State<_HeaderWidget> with ConsumerMixin {
_updateHeader(); _updateHeader();
_initMessages(); _initMessages();
// Listener für Sprachänderungen
AppLocalizations().languageNotifier.addListener(_onLanguageChanged);
}
void _onLanguageChanged() {
if (mounted) {
setState(() {
// UI wird neu aufgebaut mit neuer Sprache
});
}
} }
@override @override
@@ -466,6 +491,9 @@ class _HeaderWidgetState extends State<_HeaderWidget> with ConsumerMixin {
// Unsubscribe from all message topics // Unsubscribe from all message topics
unsubscribe(queueId: Constants.messageTopicSessionStatusInfoUpdate); unsubscribe(queueId: Constants.messageTopicSessionStatusInfoUpdate);
unsubscribe(queueId: Constants.messageTopicLocationStatusUpdated); unsubscribe(queueId: Constants.messageTopicLocationStatusUpdated);
// Entferne Listener für Sprachänderungen
AppLocalizations().languageNotifier.removeListener(_onLanguageChanged);
super.dispose(); super.dispose();
} }
+1
View File
@@ -57,6 +57,7 @@ Future<void> main() async {
MQClient.instance.declareQueue(Constants.messageTopicUpdateBadges); MQClient.instance.declareQueue(Constants.messageTopicUpdateBadges);
MQClient.instance.declareQueue(Constants.messageTopicRemoveState0JobFromMap); MQClient.instance.declareQueue(Constants.messageTopicRemoveState0JobFromMap);
MQClient.instance.declareQueue(Constants.messageTopicBWVEnabled); MQClient.instance.declareQueue(Constants.messageTopicBWVEnabled);
MQClient.instance.declareQueue(Constants.messageTopicLanguageChanged);
final dir = await getApplicationDocumentsDirectory(); final dir = await getApplicationDocumentsDirectory();
MyApp.objectBoxStore = await openStore(directory: dir.path); MyApp.objectBoxStore = await openStore(directory: dir.path);
+2 -5
View File
@@ -37,13 +37,10 @@ void showInfosPopup(SessionStatus? status) async {
} }
void onLanguageChanged(AppLanguage? newLanguage) { void onLanguageChanged(AppLanguage? newLanguage) {
if (newLanguage != null) { if (newLanguage != null && newLanguage != AppLocalizations().currentLanguage) {
AppLocalizations().setLanguage(newLanguage); AppLocalizations().setLanguage(newLanguage);
setState(() {}); setState(() {});
// Der ValueNotifier in AppLocalizations signalisiert die Änderung automatisch
// Sende Nachricht an MainPage, um UI zu aktualisieren
// Wir verwenden einen einfachen Ansatz: Die App wird neu geladen
// In einer echten App würde man hier einen State-Management-Mechanismus verwenden
} }
} }
+6
View File
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:stadtbote/tools/util.dart'; import 'package:stadtbote/tools/util.dart';
enum AppLanguage { enum AppLanguage {
@@ -33,12 +34,16 @@ class AppLocalizations {
static const String _prefsLanguageKey = 'app_language'; static const String _prefsLanguageKey = 'app_language';
// ValueNotifier für Sprachänderungen
final ValueNotifier<AppLanguage> languageNotifier = ValueNotifier<AppLanguage>(AppLanguage.german);
AppLanguage _currentLanguage = AppLanguage.german; AppLanguage _currentLanguage = AppLanguage.german;
AppLanguage get currentLanguage => _currentLanguage; AppLanguage get currentLanguage => _currentLanguage;
void setLanguage(AppLanguage language) { void setLanguage(AppLanguage language) {
_currentLanguage = language; _currentLanguage = language;
languageNotifier.value = language;
Util.preferencesSaveString(_prefsLanguageKey, language.code); Util.preferencesSaveString(_prefsLanguageKey, language.code);
} }
@@ -46,6 +51,7 @@ class AppLocalizations {
final savedCode = Util.preferencesGetString(_prefsLanguageKey, null); final savedCode = Util.preferencesGetString(_prefsLanguageKey, null);
if (savedCode != null) { if (savedCode != null) {
_currentLanguage = AppLanguage.fromCode(savedCode); _currentLanguage = AppLanguage.fromCode(savedCode);
languageNotifier.value = _currentLanguage;
} }
} }
+1
View File
@@ -25,6 +25,7 @@ class Constants {
static const String messageTopicRequestConnectionStatus = "request_connection_status"; static const String messageTopicRequestConnectionStatus = "request_connection_status";
static const String messageTopicCurrentConnectionStatus = "current_connection_status"; static const String messageTopicCurrentConnectionStatus = "current_connection_status";
static const String messageTopicBWVEnabled = "bwv_enabled"; static const String messageTopicBWVEnabled = "bwv_enabled";
static const String messageTopicLanguageChanged = "language_changed";
static const String messageShowPopup = "show_popup"; static const String messageShowPopup = "show_popup";
@@ -0,0 +1,7 @@
import 'package:stadtbote/tools/app_localizations.dart';
class LanguageChangedMessage {
final AppLanguage newLanguage;
LanguageChangedMessage(this.newLanguage);
}