# Conflicts:
#	lib/presentation/navigation/app_router.dart
#	pubspec.yaml
This commit is contained in:
2026-08-11 00:14:00 +03:00
parent c9b8d143d1
commit 182be1049b
351 changed files with 24566 additions and 22898 deletions

View File

@@ -1,75 +1,75 @@
import 'package:be_happy/domain/usecase/upload_profile_photo_usecase.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/entities/user_profile.dart';
import '../../domain/usecase/get_profile_usecase.dart';
import '../../domain/usecase/update_profile_usecase.dart';
import '../event/profile_event.dart';
import '../state/profile_state.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
final GetProfileUseCase getProfileUseCase;
final UploadProfilePhotoUsecase uploadProfilePhotoUsecase;
final UpdateProfileUseCase updateProfileUseCase;
ProfileBloc(this.getProfileUseCase,
this.uploadProfilePhotoUsecase,
this.updateProfileUseCase)
: super(ProfileState.initial()) {
on<ProfileStarted>(_onStarted);
on<ProfileUpdated>(_onUpdated);
on<ProfilePhotoUpdated>(_onPhotoUploaded);
}
Future<void> _onStarted(
ProfileStarted event,
Emitter<ProfileState> emit,
) async {
emit(state.copyWith(isLoading: true));
print("_onStarted method was start");
try {
final profile = await getProfileUseCase();
print(profile.name);
emit(state.copyWith(isLoading: false, profile: profile));
} catch (e) {
emit(state.copyWith(isLoading: false, error: "STARTED: ${e.toString()}"));
}
}
Future<void> _onUpdated(
ProfileUpdated event,
Emitter<ProfileState> emit,
) async {
final profile = await getProfileUseCase();
emit(state.copyWith(profile: profile));
}
Future<void> _onPhotoUploaded(
ProfilePhotoUpdated event,
Emitter<ProfileState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final avatarId = await uploadProfilePhotoUsecase(event.imageFile);
if (avatarId != null) {
// Отправляем PATCH запрос с новым avatarId
await updateProfileUseCase(UserProfile(
name: '',
birthDate: '',
phone: '',
email: '',
avatarId: avatarId,
));
}
final updatedProfile = await getProfileUseCase();
emit(state.copyWith(isLoading: false, profile: updatedProfile, error: null));
} catch (e) {
emit(state.copyWith(isLoading: false, error: "Ошибка загрузки: ${e.toString()}"));
}
}
}
import 'package:be_happy/domain/usecase/upload_profile_photo_usecase.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/entities/user_profile.dart';
import '../../domain/usecase/get_profile_usecase.dart';
import '../../domain/usecase/update_profile_usecase.dart';
import '../event/profile_event.dart';
import '../state/profile_state.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
final GetProfileUseCase getProfileUseCase;
final UploadProfilePhotoUsecase uploadProfilePhotoUsecase;
final UpdateProfileUseCase updateProfileUseCase;
ProfileBloc(this.getProfileUseCase,
this.uploadProfilePhotoUsecase,
this.updateProfileUseCase)
: super(ProfileState.initial()) {
on<ProfileStarted>(_onStarted);
on<ProfileUpdated>(_onUpdated);
on<ProfilePhotoUpdated>(_onPhotoUploaded);
}
Future<void> _onStarted(
ProfileStarted event,
Emitter<ProfileState> emit,
) async {
emit(state.copyWith(isLoading: true));
print("_onStarted method was start");
try {
final profile = await getProfileUseCase();
print(profile.name);
emit(state.copyWith(isLoading: false, profile: profile));
} catch (e) {
emit(state.copyWith(isLoading: false, error: "STARTED: ${e.toString()}"));
}
}
Future<void> _onUpdated(
ProfileUpdated event,
Emitter<ProfileState> emit,
) async {
final profile = await getProfileUseCase();
emit(state.copyWith(profile: profile));
}
Future<void> _onPhotoUploaded(
ProfilePhotoUpdated event,
Emitter<ProfileState> emit,
) async {
emit(state.copyWith(isLoading: true));
try {
final avatarId = await uploadProfilePhotoUsecase(event.imageFile);
if (avatarId != null) {
// Отправляем PATCH запрос с новым avatarId
await updateProfileUseCase(UserProfile(
name: '',
birthDate: '',
phone: '',
email: '',
avatarId: avatarId,
));
}
final updatedProfile = await getProfileUseCase();
emit(state.copyWith(isLoading: false, profile: updatedProfile, error: null));
} catch (e) {
emit(state.copyWith(isLoading: false, error: "Ошибка загрузки: ${e.toString()}"));
}
}
}