import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/trees_improvements.dart';
import 'package:unit2/sevices/passo/land/land_trees_improvements.dart';

part 'land_trees_improvements_event.dart';
part 'land_trees_improvements_state.dart';

class LandTreesImprovementsBloc
    extends Bloc<LandTreesImprovementsEvent, LandTreesImprovementsState> {
  LandTreesImprovementsBloc() : super(LandTreesImprovementsInitial()) {
    on<LoadLandTreesImprovements>((event, emit) async {
      emit(LandTreesImprovementsLoading());
      try {
        final trees_imp = await LandTreesImprovementsServices.instance.fetch();
        emit(LandTreesImprovementsLoaded(trees_imp));
      } catch (e) {
        emit(LandTreesImprovementsErrorState(e.toString()));
      }
    });
  }
}
