2024-11-11 16:25:25 +04:00
|
|
|
import 'package:pmu_labs/data/repositories/bosses_repository.dart';
|
|
|
|
import 'package:pmu_labs/presentation/home_page/bloc/events.dart';
|
|
|
|
import 'package:pmu_labs/presentation/home_page/bloc/state.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
2024-11-11 18:13:49 +04:00
|
|
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
2024-11-11 16:25:25 +04:00
|
|
|
final BossesRepository rep;
|
|
|
|
|
2024-11-11 18:13:49 +04:00
|
|
|
HomeBloc(this.rep) : super(const HomeState()) {
|
2024-11-11 16:25:25 +04:00
|
|
|
on<HomeLoadDataEvent>(_onLoadData);
|
|
|
|
}
|
|
|
|
|
2024-11-11 18:13:49 +04:00
|
|
|
Future<void> _onLoadData(
|
|
|
|
HomeLoadDataEvent event, Emitter<HomeState> emit) async {
|
|
|
|
emit(state.copyWith(isLoading: true));
|
|
|
|
|
|
|
|
String? error;
|
|
|
|
|
|
|
|
final data = await rep.loadData(
|
|
|
|
q: event.search,
|
|
|
|
onError: (e) => error = e,
|
|
|
|
);
|
|
|
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
isLoading: false,
|
|
|
|
data: data,
|
|
|
|
error: error,
|
|
|
|
));
|
2024-11-11 16:25:25 +04:00
|
|
|
}
|
2024-11-11 18:13:49 +04:00
|
|
|
}
|