Hi all,
These changes described in this breaking change proposal have been made and will land in the upcoming Dart 2.5.0 release.
Error cases (and how to fix them):
If you see the following errors in your code, here's what you do to fix them:
- Error: "The argument type 'Utf8Decoder' can't be assigned to the parameter type 'StreamTransformer<Uint8List, dynamic>'."
- How to fix: Use StreamTransformer.bind(Stream) instead of Stream.transform(StreamTransformer).
- Example:
- Before: foo.transform(utf8.decoder)...
- After: utf8.decoder.bind(foo)...
- Extra notes:
- This applies to any StreamTransformer<List<int>, ...>, not just Utf8Decoder. Other examples include base64.encoder and gzip.decoder. In these cases, the error message will be slightly different, such as "The argument type 'Converter<List<int>, String>' can't be assigned to the parameter type 'StreamTransformer<Uint8List, dynamic>'"
- This error can happen at runtime as well, with the following error message: "type 'Utf8Decoder' is not a subtype of type 'StreamTransformer' of 'streamTransformer'". The fix is the same.
- Error: "The argument type 'IOSink' can't be assigned to the parameter type 'StreamConsumer<Uint8List>'"
- How to fix: Cast your stream instance to a Stream<List<int>> before calling .pipe() on the stream.
- Example:
- Before: foo.pipe(consumer)...
- After: foo.cast<List<int>>().pipe(consumer)...
- Extra notes:
- This applies to any StreamConsumer<List<int>>, not just IOSink. Other examples include WebSocket and StreamController<List<int>>.
Full listing of changes:
The following is a full accounting of the changes that have been implemented:
- Now declares return type of Uint8List (was List<int>)
- Utf8Codec.encode()
- BytesBuilder.takeBytes()
- BytesBuilder.toBytes()
- File.readAsBytesSync()
- RandomAccessFile.readSync()
- RawSocket.read()
- InternetAddress.rawAddress
- Datagram.data
- Now declares return type of Future<Uint8List> (was Future<List<int>>)
- File.readAsBytes()
- RandomAccessFile.read()
- Now declares return type of specific typed list (was generic List<int>)
- Uint8List.sublist()
- Int8List.sublist()
- Uint8ClampedList.sublist()
- Int16List.sublist()
- Uint16List.sublist()
- Int32List.sublist()
- Uint32List.sublist()
- Int64List.sublist()
- Uint64List.sublist()
- Float32List.sublist()
- Float64List.sublist()
- Float32x4List.sublist()
- Int32x4List.sublist()
- Float64x2List.sublist()
- Now declares a return type of Stream<Uint8List> (was Stream<List<int>>)
- Now implements Stream<Uint8List> (was Stream<List<int>>)
- HttpRequest (dart:io)
- HttpClientResponse (dart:io)
- Socket (dart:io)
I have
updated public packages with forwards-compatible fixes where possible. For cases that I didn't catch, or for cases where your code is not published to Pub, you'll want to look out for the failures described in the "Summary" section of this email and apply the corresponding fixes.
Cheers,
-T