before rediense
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
@@ -11,27 +11,33 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
ProfileBloc({required UserRepository userRepository})
|
||||
: _userRepository = userRepository,
|
||||
super(UpdateUserInfoInitial()) {
|
||||
on<UploadPicture>(_onUploadPicture);
|
||||
// on<UploadPicture>(_onUploadPicture);
|
||||
on<UpdateUserInfo>(_onUpdateUserInfo);
|
||||
}
|
||||
|
||||
void _onUploadPicture(UploadPicture event, Emitter<ProfileState> emit) async {
|
||||
emit(UploadPictureLoading());
|
||||
try {
|
||||
String userImage =
|
||||
await _userRepository.uploadPicture(event.file, event.userId);
|
||||
emit(UploadPictureSuccess(userImage));
|
||||
} catch (e) {
|
||||
emit(UploadPictureFailure());
|
||||
}
|
||||
}
|
||||
// void _onUploadPicture(UploadPicture event, Emitter<ProfileState> emit) async {
|
||||
// emit(UploadPictureLoading());
|
||||
// try {
|
||||
// String userImage =
|
||||
// await _userRepository.uploadPicture(event.file, event.userId);
|
||||
// emit(UploadPictureSuccess(userImage));
|
||||
// } catch (e) {
|
||||
// emit(UploadPictureFailure());
|
||||
// }
|
||||
// }
|
||||
|
||||
void _onUpdateUserInfo(
|
||||
UpdateUserInfo event, Emitter<ProfileState> emit) async {
|
||||
emit(UpdateUserInfoLoading());
|
||||
try {
|
||||
await _userRepository.updateUserInfo(event.userId, {
|
||||
await _userRepository.updateUserInfo(event.userId, event.picture, {
|
||||
'name': event.name,
|
||||
// 'picture': event.picture,
|
||||
'nickname': event.nickname,
|
||||
'email': event.email,
|
||||
'phone': event.phone,
|
||||
'birthDate': event.birthDate,
|
||||
'gender': event.gender
|
||||
});
|
||||
emit(const UpdateUserInfoSuccess());
|
||||
} catch (e) {
|
||||
|
||||
@@ -4,7 +4,7 @@ abstract class ProfileEvent extends Equatable {
|
||||
const ProfileEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class UploadPicture extends ProfileEvent {
|
||||
@@ -14,15 +14,31 @@ class UploadPicture extends ProfileEvent {
|
||||
const UploadPicture(this.file, this.userId);
|
||||
|
||||
@override
|
||||
List<Object> get props => [file, userId];
|
||||
List<Object?> get props => [file, userId];
|
||||
}
|
||||
|
||||
class UpdateUserInfo extends ProfileEvent {
|
||||
final String userId;
|
||||
final String name;
|
||||
final String picture;
|
||||
final String? name;
|
||||
final String? nickname;
|
||||
final String? email;
|
||||
final String? phone;
|
||||
final String? birthDate;
|
||||
final String? gender;
|
||||
|
||||
const UpdateUserInfo(this.userId, this.name);
|
||||
const UpdateUserInfo({
|
||||
required this.userId,
|
||||
required this.picture,
|
||||
this.name,
|
||||
this.nickname,
|
||||
this.email,
|
||||
this.phone,
|
||||
this.birthDate,
|
||||
this.gender,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [userId, name];
|
||||
List<Object?> get props =>
|
||||
[userId, name, nickname, email, phone, picture, birthDate, gender];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user