Fwd: Breaking change #36900: Declare return types of Uint8List

534 views
Skip to first unread message

Todd Volkert

unread,
Jul 7, 2019, 3:43:07 PM7/7/19
to flutt...@googlegroups.com
[bcc flutter-announce]

Hi Flutter users,

The changes described below will land in Flutter 1.8.1 and above.    If you have any questions or comments, please let me know on the associated issue: https://github.com/dart-lang/sdk/issues/36900

Cheers,
-T

---------- Forwarded message ---------
From: Todd Volkert <tvol...@google.com>
Date: Sun, Jul 7, 2019 at 12:37 PM
Subject: Re: Breaking change #36900: Declare return types of Uint8List
To: <anno...@dartlang.org>


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>>)
    • File.openRead()
  • 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.

If you have any trouble, please comment on the associated issue (https://github.com/dart-lang/sdk/issues/36900), and I'll be happy to help.

Cheers,
-T


On Thu, May 9, 2019 at 10:15 PM Todd Volkert <tvol...@google.com> wrote:
#36900 proposes to update the return values of some methods in the Dart SDK from generic numeric list types (e.g. List<int>) to more specific list types (e.g. Uint8List) -- where all methods in question are already returning the more specific list type.

See https://github.com/dart-lang/sdk/issues/36900 for more info.

Please leave comments in the issue linked above if this breaking change poses a severe problem for you.

Cheers,
-T

Bhanuka Isuru

unread,
Jul 11, 2019, 6:28:18 AM7/11/19
to Flutter Development (flutter-dev)
do you fix this issue?
Reply all
Reply to author
Forward
0 new messages