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.

32 lines
826B

  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(Function(dynamic) onSuccess, Function(String) onError) async {
  8. try {
  9. _repository.getHarvests().then((value) {
  10. onSuccess(value);
  11. _getHarvestFetcher.sink.add(value);
  12. }).catchError((onError) {
  13. _getHarvestFetcher.addError(onError);
  14. onError(onError);
  15. });
  16. } catch (e) {
  17. _getHarvestFetcher.addError(e);
  18. onError('');
  19. }
  20. }
  21. void dispose() async {
  22. await _getHarvestFetcher.drain();
  23. _getHarvestFetcher.close();
  24. }
  25. }
  26. final getHarvestBloc = GetHarvestBloc();