This commit refactors the user management system to utilize UserCubit, improving state management and separation of concerns. - Replaces UserService with UserCubit for managing user state. - Introduces AppSettings and GlobalSettings models and repositories for managing app-level settings and configurations. - Modifies dependency injection to register the new repositories and cubits. - Updates UI components (LoginPage, SettingsPage, HomePage, AddTransactionDialog, CategoryListPage, TagListPage) to interact with UserCubit and SettingsCubit. - Removes direct dependency on UserRepository in favor of UserCubit for accessing user information. - Streamlines the authentication process by using UserCubit to handle user creation and login. - Improves settings management by using dedicated repositories and cubits for app settings.
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
import 'package:hive_ce/hive.dart';
|
|
|
|
import '../../models/global_settings.dart';
|
|
import 'interfaces/iglobal_settings_repository.dart';
|
|
|
|
/// Реализация репозитория глобальных настроек с использованием Hive
|
|
class HiveGlobalSettingsRepository implements IGlobalSettingsRepository {
|
|
static const String _settingsKey = 'global_settings';
|
|
final Box<GlobalSettings> _box;
|
|
|
|
HiveGlobalSettingsRepository(this._box);
|
|
|
|
@override
|
|
Future<String?> getCurrentUserId() async {
|
|
try {
|
|
final settings = _box.get(_settingsKey);
|
|
return settings?.currentUserId;
|
|
} catch (e) {
|
|
throw Exception('Ошибка получения ID текущего пользователя: $e');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> setCurrentUserId(String? userId) async {
|
|
try {
|
|
final settings = _box.get(_settingsKey) ?? GlobalSettings();
|
|
settings.currentUserId = userId;
|
|
await _box.put(_settingsKey, settings);
|
|
} catch (e) {
|
|
throw Exception('Ошибка сохранения ID текущего пользователя: $e');
|
|
}
|
|
}
|
|
}
|