Link between front-end and back-end

This commit is contained in:
2025-07-09 12:41:00 +02:00
parent 6735ddb5fd
commit 1b261c08bb
31 changed files with 5507 additions and 40 deletions

View File

@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LocaleProvider extends ChangeNotifier {
Locale? _locale;
Locale? get locale => _locale;
LocaleProvider() {
_loadLocale();
}
void _loadLocale() async {
final prefs = await SharedPreferences.getInstance();
final languageCode = prefs.getString('languageCode');
final countryCode = prefs.getString('countryCode');
if (languageCode != null) {
_locale = Locale(languageCode, countryCode);
} else {
_locale = null;
}
notifyListeners();
}
void setLocale(Locale newLocale) async {
if (_locale == newLocale) return;
_locale = newLocale;
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.setString('languageCode', newLocale.languageCode);
if (newLocale.countryCode != null) {
await prefs.setString('countryCode', newLocale.countryCode!);
} else {
await prefs.remove('countryCode');
}
}
void clearLocale() async {
_locale = null;
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.remove('languageCode');
await prefs.remove('countryCode');
}
}

View File

@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ThemeProvider extends ChangeNotifier {
ThemeMode _themeMode = ThemeMode.system;
ThemeMode get themeMode => _themeMode;
ThemeProvider() {
_loadThemeMode();
}
void _loadThemeMode() async {
final prefs = await SharedPreferences.getInstance();
final themeIndex = prefs.getInt('themeMode') ?? 0;
_themeMode = ThemeMode.values[themeIndex];
notifyListeners();
}
void setThemeMode(ThemeMode mode) async {
if (_themeMode != mode) {
_themeMode = mode;
notifyListeners();
final prefs = await SharedPreferences.getInstance();
await prefs.setInt('themeMode', mode.index);
}
}
}