after
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'profile_event.dart';
|
||||
part 'profile_state.dart';
|
||||
|
||||
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
final UserRepository _userRepository;
|
||||
|
||||
ProfileBloc({required UserRepository userRepository})
|
||||
: _userRepository = userRepository,
|
||||
super(UpdateUserInfoInitial()) {
|
||||
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 _onUpdateUserInfo(
|
||||
UpdateUserInfo event, Emitter<ProfileState> emit) async {
|
||||
emit(UpdateUserInfoLoading());
|
||||
try {
|
||||
await _userRepository.updateUserInfo(event.userId, {
|
||||
'name': event.name,
|
||||
});
|
||||
emit(const UpdateUserInfoSuccess());
|
||||
} catch (e) {
|
||||
emit(UpdateUserInfoFailure());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
part of 'profile_bloc.dart';
|
||||
|
||||
abstract class ProfileEvent extends Equatable {
|
||||
const ProfileEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class UploadPicture extends ProfileEvent {
|
||||
final String file;
|
||||
final String userId;
|
||||
|
||||
const UploadPicture(this.file, this.userId);
|
||||
|
||||
@override
|
||||
List<Object> get props => [file, userId];
|
||||
}
|
||||
|
||||
class UpdateUserInfo extends ProfileEvent {
|
||||
final String userId;
|
||||
final String name;
|
||||
|
||||
const UpdateUserInfo(this.userId, this.name);
|
||||
|
||||
@override
|
||||
List<Object> get props => [userId, name];
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
part of 'profile_bloc.dart';
|
||||
|
||||
abstract class ProfileState extends Equatable {
|
||||
const ProfileState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class UpdateUserInfoInitial extends ProfileState {}
|
||||
|
||||
class UploadPictureFailure extends ProfileState {}
|
||||
|
||||
class UploadPictureLoading extends ProfileState {}
|
||||
|
||||
class UploadPictureSuccess extends ProfileState {
|
||||
final String userImage;
|
||||
|
||||
const UploadPictureSuccess(this.userImage);
|
||||
|
||||
@override
|
||||
List<Object> get props => [userImage];
|
||||
}
|
||||
|
||||
class UpdateUserInfoFailure extends ProfileState {}
|
||||
|
||||
class UpdateUserInfoLoading extends ProfileState {}
|
||||
|
||||
class UpdateUserInfoSuccess extends ProfileState {
|
||||
const UpdateUserInfoSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
Reference in New Issue
Block a user