2023-02-01 08:03:05 +00:00
|
|
|
import 'package:bloc/bloc.dart';
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
import 'package:unit2/model/profile/profileInfomation.dart';
|
|
|
|
import 'package:unit2/sevices/profile/profile_service.dart';
|
|
|
|
part 'profile_event.dart';
|
|
|
|
part 'profile_state.dart';
|
|
|
|
|
|
|
|
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|
|
|
ProfileBloc() : super(ProfileInitial()) {
|
2023-02-27 06:26:27 +00:00
|
|
|
ProfileInformation? globalProfileInformation;
|
2023-02-01 08:03:05 +00:00
|
|
|
on<LoadProfile>((event, emit) async {
|
2023-03-02 00:40:47 +00:00
|
|
|
try {
|
|
|
|
emit(ProfileLoading());
|
|
|
|
ProfileInformation? profileInformation =
|
|
|
|
await ProfileService.instance.getProfile(event.token, event.userID);
|
|
|
|
globalProfileInformation = profileInformation;
|
|
|
|
emit(ProfileLoaded(profileInformation: globalProfileInformation!));
|
|
|
|
} catch (e) {
|
|
|
|
emit(ProfileErrorState(mesage: e.toString()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-02-01 08:03:05 +00:00
|
|
|
}
|
|
|
|
}
|