fetchAllResponses method

Future<void> fetchAllResponses()

Implementation

Future<void> fetchAllResponses() async {
  _getAllResponsesState = RequestState.loading;
  notifyListeners();

  final result = await getLogUseCase?.execute();

  result?.fold(
    (failure) {
      _getAllResponsesState = RequestState.error;
      _message = failure.message;
      notifyListeners();
    },
    (responses) {
      _subscription = responses.listen((event) {
        _getAllResponses = event;
        _getAllResponses.sort(
          (call1, call2) =>
              call2.request?.createdAt?.compareTo(call1.request!.createdAt!) ??
              -1,
        );
        _getAllResponsesState = RequestState.loaded;
        notifyListeners();
      });
    },
  );
}