passo_mobile_app/lib/bloc/profile/profile_bloc.dart

27 lines
864 B
Dart

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()) {
ProfileInformation? globalProfileInformation;
on<LoadProfile>((event, emit) async {
emit(ProfileLoading());
try {
ProfileInformation? profileInformation =
await ProfileService.instance.getProfile(event.token, event.userID);
globalProfileInformation = profileInformation;
emit(ProfileLoaded(profileInformation: globalProfileInformation!));
} catch (e) {
emit(ProfileErrorState(mesage: e.toString()));
}
});
}
}