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.

33 lines
832B

  1. import 'package:farm_tpf/data/repository/repository.dart';
  2. import 'package:rxdart/rxdart.dart';
  3. class GetHarvestBloc {
  4. final _repository = Repository();
  5. final _getHarvestFetcher = PublishSubject<dynamic>();
  6. Stream<dynamic> get actions => _getHarvestFetcher.stream;
  7. void getHarvests(
  8. Function(dynamic) onSuccess, Function(String) onError) async {
  9. try {
  10. _repository.getHarvests().then((value) {
  11. onSuccess(value);
  12. _getHarvestFetcher.sink.add(value);
  13. }).catchError((onError) {
  14. _getHarvestFetcher.addError(onError);
  15. onError(onError);
  16. });
  17. } catch (e) {
  18. _getHarvestFetcher.addError(e);
  19. onError(e);
  20. }
  21. }
  22. void dispose() async {
  23. await _getHarvestFetcher.drain();
  24. _getHarvestFetcher.close();
  25. }
  26. }
  27. final getHarvestBloc = GetHarvestBloc();