feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'settings_state.dart';
|
||||
|
||||
/// الإعدادات العامة: الثيم + اللغة.
|
||||
/// يُحفظ محلياً عبر SharedPreferences (ليس سراً — docs/26 §4).
|
||||
class SettingsCubit extends Cubit<SettingsState> {
|
||||
static const _kThemeKey = 'settings_theme_mode';
|
||||
static const _kLocaleKey = 'settings_locale';
|
||||
|
||||
SettingsCubit() : super(const SettingsState()) {
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final themeIndex = prefs.getInt(_kThemeKey) ?? 0;
|
||||
final localeCode = prefs.getString(_kLocaleKey) ?? 'ar';
|
||||
|
||||
emit(state.copyWith(
|
||||
themeMode: ThemeMode.values[themeIndex],
|
||||
locale: Locale(localeCode),
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> setThemeMode(ThemeMode mode) async {
|
||||
emit(state.copyWith(themeMode: mode));
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_kThemeKey, mode.index);
|
||||
}
|
||||
|
||||
Future<void> setLocale(Locale locale) async {
|
||||
emit(state.copyWith(locale: locale));
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_kLocaleKey, locale.languageCode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user