You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
864B

  1. import 'package:farm_tpf/data/api/app_exception.dart';
  2. import 'package:farm_tpf/data/repository/repository.dart';
  3. import 'package:rxdart/rxdart.dart';
  4. class GetPlotInfoBloc {
  5. final _repository = Repository();
  6. final _getPlotInfoFetcher = PublishSubject<dynamic>();
  7. Stream<dynamic> get actions => _getPlotInfoFetcher.stream;
  8. void getPlotInfo(
  9. int cropId, Function(dynamic) onSuccess, Function(String) onError) async {
  10. _repository.getPlotDetail(cropId).then((value) {
  11. onSuccess(value);
  12. _getPlotInfoFetcher.sink.add(value);
  13. }).catchError((onError) {
  14. onError(AppException.handleError(onError));
  15. _getPlotInfoFetcher.addError(AppException.handleError(onError));
  16. });
  17. }
  18. void dispose() async {
  19. await _getPlotInfoFetcher.drain();
  20. _getPlotInfoFetcher.close();
  21. }
  22. }
  23. final getPlotInfoBloc = GetPlotInfoBloc();