diff --git a/lib/features/profile/domain/bloc/profile_bloc.dart b/lib/features/profile/domain/bloc/profile_bloc.dart index 1fe03fc..93d5810 100644 --- a/lib/features/profile/domain/bloc/profile_bloc.dart +++ b/lib/features/profile/domain/bloc/profile_bloc.dart @@ -16,9 +16,14 @@ class ProfileBloc extends Bloc { ProfileBloc(this._profileRepository) : super(ProfileInitialState()) { // Регистрируем обработчики событий в конструкторе on((event, emit) async { + // Обрабатываем событие загрузки профиля if (event is ProfileFetchProfileEvent) { await _fetchProfile(event, emit); } + // Обрабатываем событие выхода из профиля + else if (event is ProfileLogoutProfileEvent) { + await _logout(event, emit); + } }); } @@ -44,6 +49,7 @@ class ProfileBloc extends Bloc { final data = await _profileRepository.fetchUserProfile(event.id); emit(ProfileSuccessState(data: data)); } on Object catch (error, stackTrace) { + // Обработка ошибки при загрузке профиля emit( ProfileErrorState( message: 'Ошибка при загрузке профиля', @@ -51,6 +57,19 @@ class ProfileBloc extends Bloc { stackTrace: stackTrace, ), ); + // Пробрасываем исключение дальше, для логирования или обработки + rethrow; } } + + /// Метод для выхода из профиля пользователя. + Future _logout( + ProfileLogoutProfileEvent event, + Emitter emit, + ) async { + // Здесь можно добавить логику выхода из профиля + // Например, очистка токенов, данных пользователя и т.д. + // В данном примере просто эмитим начальное состояние + emit(ProfileInitialState()); + } } diff --git a/lib/features/profile/domain/bloc/profile_event.dart b/lib/features/profile/domain/bloc/profile_event.dart index 69c50c8..4410dfd 100644 --- a/lib/features/profile/domain/bloc/profile_event.dart +++ b/lib/features/profile/domain/bloc/profile_event.dart @@ -1,16 +1,37 @@ part of 'profile_bloc.dart'; +/// {@template profile_event} +/// События для управления состоянием профиля пользователя. +/// {@endtemplate} sealed class ProfileEvent extends Equatable { + /// {@macro profile_event} const ProfileEvent(); @override List get props => []; } +/// {@template profile_event} +/// Событие для загрузки профиля пользователя. +/// {@endtemplate} final class ProfileFetchProfileEvent extends ProfileEvent { + /// {@macro profile_event} const ProfileFetchProfileEvent({required this.id}); + + /// ID пользователя для загрузки профиля final String id; @override List get props => [id]; } + +/// {@template profile_logout_event} +/// Событие для выхода из профиля пользователя. +/// {@endtemplate} +final class ProfileLogoutProfileEvent extends ProfileEvent { + /// {@macro profile_logout_event} + const ProfileLogoutProfileEvent(); + + @override + List get props => []; +}