24 lines
715 B
Dart
24 lines
715 B
Dart
import 'package:bloc/bloc.dart';
|
|
import 'package:equatable/equatable.dart';
|
|
import '../../data/dtos/hero_dto.dart';
|
|
import '../../data/repositories/hero_repository.dart';
|
|
import 'hero_detail_state.dart';
|
|
import 'hero_detail_events.dart';
|
|
|
|
// BLoC
|
|
class HeroDetailBloc extends Bloc<HeroDetailEvent, HeroDetailState> {
|
|
final HeroRepository heroRepository;
|
|
|
|
HeroDetailBloc(this.heroRepository) : super(HeroDetailInitial()) {
|
|
on<FetchHeroDetails>((event, emit) async {
|
|
emit(HeroDetailLoading());
|
|
try {
|
|
final hero = await heroRepository.getHeroDetails(event.heroId);
|
|
emit(HeroDetailLoaded(hero));
|
|
} catch (e) {
|
|
emit(HeroDetailError(e.toString()));
|
|
}
|
|
});
|
|
}
|
|
}
|