jsonObjects<T> method

Stream<T> jsonObjects<T>(
  1. String method,
  2. String path, {
  3. int? pages,
  4. Map<String, String>? headers,
  5. Map<String, dynamic>? params,
  6. String? body,
  7. int statusCode = 200,
  8. String? preview,
  9. String? arrayKey,
})

Implementation

Stream<T> jsonObjects<T>(
  String method,
  String path, {
  int? pages,
  Map<String, String>? headers,
  Map<String, dynamic>? params,
  String? body,
  int statusCode = 200,
  String? preview,
  String? arrayKey,
}) async* {
  headers ??= {};
  if (preview != null) {
    headers['Accept'] = preview;
  }
  headers.putIfAbsent('Accept', () => v3ApiMimeType);

  await for (final response in fetchStreamed(
    method,
    path,
    pages: pages,
    headers: headers,
    params: params,
    body: body,
    statusCode: statusCode,
  )) {
    final json = arrayKey == null
        ? jsonDecode(response.body) as List?
        : (jsonDecode(response.body) as Map)[arrayKey];

    for (final item in json) {
      yield (item as T?)!;
    }
  }
}