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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum SettingsStatus { loaded, error }
|
||||
|
||||
class SettingsState extends Equatable {
|
||||
final SettingsStatus status;
|
||||
final ThemeMode themeMode;
|
||||
final Locale locale;
|
||||
|
||||
const SettingsState({
|
||||
this.status = SettingsStatus.loaded,
|
||||
this.themeMode = ThemeMode.system,
|
||||
this.locale = const Locale('ar'),
|
||||
});
|
||||
|
||||
SettingsState copyWith({
|
||||
SettingsStatus? status,
|
||||
ThemeMode? themeMode,
|
||||
Locale? locale,
|
||||
}) {
|
||||
return SettingsState(
|
||||
status: status ?? this.status,
|
||||
themeMode: themeMode ?? this.themeMode,
|
||||
locale: locale ?? this.locale,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, themeMode, locale];
|
||||
}
|
||||
Reference in New Issue
Block a user