getCachedBillsAsStream method

Future<AnybillResult<Stream<List<BillBaseDto>>>> getCachedBillsAsStream()

Retrieve a Stream<List<BillBaseDto>> with the bills of the current authenticated user using the database. Important!!! Cancel the subscription to avoid memory leaks.

Returns a AnybillResult.success that contains a stream to listen to changes of the bill cache.

Throws a AnybillResult.failure with the specified information gained from the API. This could be a DioException when a generic errors occurred or a different Exception for critical errors that couldn't be caught.

Implementation

Future<AnybillResult<Stream<List<BillBaseDto>>>>
    getCachedBillsAsStream() async {
  AnybillLogger.info("Tried to get bill database stream");
  try {
    final steam = await _billStore.getBillsStream();

    return AnybillResult.success(
      HttpStatus.ok,
      data: steam,
    );
  }
  // ----------------------------------------------------------------
  catch (error, stacktrace) {
    AnybillLogger.error(
      error: error,
      stacktrace: stacktrace,
      library: runtimeType.toString(),
      event: "getCachedBillsAsStream",
    );
    return AnybillResult.failure(
      type: AnybillErrorType.unknown,
      message: error.toString(),
    );
  }
}