26 lines
691 B
Dart
26 lines
691 B
Dart
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
|
import 'package:pmd_lab/presentation/home_page/bloc/events.dart';
|
||
|
import 'package:pmd_lab/presentation/home_page/bloc/state.dart';
|
||
|
import 'package:pmd_lab/repositories/potter_repository.dart';
|
||
|
|
||
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||
|
final PotterRepository repo;
|
||
|
|
||
|
HomeBloc(this.repo) : super(const HomeState()) {
|
||
|
on<HomeLoadDataEvent>(_onLoadData);
|
||
|
}
|
||
|
|
||
|
Future<void> _onLoadData(HomeLoadDataEvent event, Emitter<HomeState> emit) async {
|
||
|
emit(state.copyWith(isLoading: true));
|
||
|
|
||
|
final data = await repo.loadData(q: event.search);
|
||
|
|
||
|
emit(state.copyWith(
|
||
|
isLoading: false,
|
||
|
data: data,
|
||
|
));
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|