- Flutter frontend with Provider state management - FastAPI backend with SQLAlchemy ORM - Internationalization support (EN/DE) - Clean Architecture folder structure - GoRouter for navigation - GetIt for dependency injection
43 lines
1.2 KiB
Dart
43 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
abstract class SettingsLocalDataSource {
|
|
Locale? getLocale();
|
|
Future<void> setLocale(Locale locale);
|
|
ThemeMode getThemeMode();
|
|
Future<void> setThemeMode(ThemeMode mode);
|
|
}
|
|
|
|
class SettingsLocalDataSourceImpl implements SettingsLocalDataSource {
|
|
final SharedPreferences sharedPreferences;
|
|
|
|
static const String _localeKey = 'locale';
|
|
static const String _themeModeKey = 'theme_mode';
|
|
|
|
SettingsLocalDataSourceImpl({required this.sharedPreferences});
|
|
|
|
@override
|
|
Locale? getLocale() {
|
|
final localeCode = sharedPreferences.getString(_localeKey);
|
|
if (localeCode == null) return null;
|
|
return Locale(localeCode);
|
|
}
|
|
|
|
@override
|
|
Future<void> setLocale(Locale locale) async {
|
|
await sharedPreferences.setString(_localeKey, locale.languageCode);
|
|
}
|
|
|
|
@override
|
|
ThemeMode getThemeMode() {
|
|
final index = sharedPreferences.getInt(_themeModeKey);
|
|
if (index == null) return ThemeMode.system;
|
|
return ThemeMode.values[index];
|
|
}
|
|
|
|
@override
|
|
Future<void> setThemeMode(ThemeMode mode) async {
|
|
await sharedPreferences.setInt(_themeModeKey, mode.index);
|
|
}
|
|
}
|