Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ $returnAsyncWrapper httpResponse;
// we extract the stream from it
blocks.add(
declareFinal(_resultVar)
.assign(refer('await $_dioVar.fetch<ResponseBody>').call([options]))
.assign(refer('$_dioVar.fetch<ResponseBody>').call([options]))
.statement,
);

Expand All @@ -1058,15 +1058,19 @@ $returnAsyncWrapper httpResponse;
);
blocks.add(
Code('''
final $_valueVar = $_resultVar.data!.stream.map(utf8.decode);
final $_valueVar = $_resultVar.asStream().asyncExpand(
(response) => response.data!.stream.map(utf8.decode),
);
$returnAsyncWrapper* $_valueVar;
'''),
);
} else {
// For Stream<Uint8List>, return the raw stream
blocks.add(
Code('''
final $_valueVar = $_resultVar.data!.stream;
final $_valueVar = $_resultVar.asStream().asyncExpand(
(response) => response.data!.stream,
);
$returnAsyncWrapper* $_valueVar;
'''),
);
Expand Down
12 changes: 8 additions & 4 deletions generator/test/src/generator_test_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,10 @@ abstract class TestQueryParamExtensionTypeWithToJsonNullable {
)
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
);
final _result = await _dio.fetch<ResponseBody>(_options);
final _value = _result.data!.stream;
final _result = _dio.fetch<ResponseBody>(_options);
final _value = _result.asStream().asyncExpand(
(response) => response.data!.stream,
);
yield* _value;
}
''',
Expand Down Expand Up @@ -3234,8 +3236,10 @@ abstract class TestBareTypeParameterNullable {

@ShouldGenerate(
'''
final _result = await _dio.fetch<ResponseBody>(_options);
final _value = _result.data!.stream.map(utf8.decode);
final _result = _dio.fetch<ResponseBody>(_options);
final _value = _result.asStream().asyncExpand(
(response) => response.data!.stream.map(utf8.decode),
);
yield* _value;
''',
contains: true,
Expand Down
Loading