mirror of
https://github.com/smmarty/friflex_flutter_starter.git
synced 2025-12-22 01:20:46 +00:00
feat(profile): добавить обработку события выхода из профиля и rethrow (#17)
Co-authored-by: PetrovY <y.petrov@friflex.com>
This commit is contained in:
@@ -16,9 +16,14 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
ProfileBloc(this._profileRepository) : super(ProfileInitialState()) {
|
ProfileBloc(this._profileRepository) : super(ProfileInitialState()) {
|
||||||
// Регистрируем обработчики событий в конструкторе
|
// Регистрируем обработчики событий в конструкторе
|
||||||
on<ProfileEvent>((event, emit) async {
|
on<ProfileEvent>((event, emit) async {
|
||||||
|
// Обрабатываем событие загрузки профиля
|
||||||
if (event is ProfileFetchProfileEvent) {
|
if (event is ProfileFetchProfileEvent) {
|
||||||
await _fetchProfile(event, emit);
|
await _fetchProfile(event, emit);
|
||||||
}
|
}
|
||||||
|
// Обрабатываем событие выхода из профиля
|
||||||
|
else if (event is ProfileLogoutProfileEvent) {
|
||||||
|
await _logout(event, emit);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +49,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
final data = await _profileRepository.fetchUserProfile(event.id);
|
final data = await _profileRepository.fetchUserProfile(event.id);
|
||||||
emit(ProfileSuccessState(data: data));
|
emit(ProfileSuccessState(data: data));
|
||||||
} on Object catch (error, stackTrace) {
|
} on Object catch (error, stackTrace) {
|
||||||
|
// Обработка ошибки при загрузке профиля
|
||||||
emit(
|
emit(
|
||||||
ProfileErrorState(
|
ProfileErrorState(
|
||||||
message: 'Ошибка при загрузке профиля',
|
message: 'Ошибка при загрузке профиля',
|
||||||
@@ -51,6 +57,19 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||||||
stackTrace: stackTrace,
|
stackTrace: stackTrace,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
// Пробрасываем исключение дальше, для логирования или обработки
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Метод для выхода из профиля пользователя.
|
||||||
|
Future<void> _logout(
|
||||||
|
ProfileLogoutProfileEvent event,
|
||||||
|
Emitter<ProfileState> emit,
|
||||||
|
) async {
|
||||||
|
// Здесь можно добавить логику выхода из профиля
|
||||||
|
// Например, очистка токенов, данных пользователя и т.д.
|
||||||
|
// В данном примере просто эмитим начальное состояние
|
||||||
|
emit(ProfileInitialState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,37 @@
|
|||||||
part of 'profile_bloc.dart';
|
part of 'profile_bloc.dart';
|
||||||
|
|
||||||
|
/// {@template profile_event}
|
||||||
|
/// События для управления состоянием профиля пользователя.
|
||||||
|
/// {@endtemplate}
|
||||||
sealed class ProfileEvent extends Equatable {
|
sealed class ProfileEvent extends Equatable {
|
||||||
|
/// {@macro profile_event}
|
||||||
const ProfileEvent();
|
const ProfileEvent();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// {@template profile_event}
|
||||||
|
/// Событие для загрузки профиля пользователя.
|
||||||
|
/// {@endtemplate}
|
||||||
final class ProfileFetchProfileEvent extends ProfileEvent {
|
final class ProfileFetchProfileEvent extends ProfileEvent {
|
||||||
|
/// {@macro profile_event}
|
||||||
const ProfileFetchProfileEvent({required this.id});
|
const ProfileFetchProfileEvent({required this.id});
|
||||||
|
|
||||||
|
/// ID пользователя для загрузки профиля
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [id];
|
List<Object> get props => [id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// {@template profile_logout_event}
|
||||||
|
/// Событие для выхода из профиля пользователя.
|
||||||
|
/// {@endtemplate}
|
||||||
|
final class ProfileLogoutProfileEvent extends ProfileEvent {
|
||||||
|
/// {@macro profile_logout_event}
|
||||||
|
const ProfileLogoutProfileEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user