Skip to content

Commit

Permalink
Prepare for utf8.encode() to return more precise Uint8List type (#4342)
Browse files Browse the repository at this point in the history
To avoid analyzer warnings when `utf8.encode()` will return the more precise `Uint8List` type, we use `const Utf8Encoder().convert()` which already returns `Uint8List`

See dart-lang/sdk#52801
  • Loading branch information
mkustermann committed Jun 30, 2023
1 parent 03c73a6 commit cbbc2fb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import 'package:integration_test/integration_test.dart';

const String expectedStringContents = 'Hello, world!';
const String otherStringContents = 'Hello again, world!';
final Uint8List bytes = utf8.encode(expectedStringContents) as Uint8List;
final Uint8List otherBytes = utf8.encode(otherStringContents) as Uint8List;
final Uint8List bytes = const Utf8Encoder().convert(expectedStringContents);
final Uint8List otherBytes = const Utf8Encoder().convert(otherStringContents);
final Map<String, dynamic> options = <String, dynamic>{
'type': 'text/plain',
'lastModified': DateTime.utc(2017, 12, 13).millisecondsSinceEpoch,
Expand Down
3 changes: 2 additions & 1 deletion packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## NEXT
## 1.0.10

* Fixes stale ignore: prefer_const_constructors.
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
* Changes package internals to avoid explicit `as Uint8List` downcast.

## 1.0.9

Expand Down
2 changes: 1 addition & 1 deletion packages/rfw/lib/src/dart/binary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class _BlobEncoder {
}

void _writeString(String value) {
final Uint8List buffer = utf8.encode(value) as Uint8List;
final Uint8List buffer = const Utf8Encoder().convert(value);
_writeInt64(buffer.length);
bytes.add(buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rfw/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: rfw
description: "Remote Flutter widgets: a library for rendering declarative widget description files at runtime."
repository: https://github.com/flutter/packages/tree/main/packages/rfw
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+rfw%22
version: 1.0.9
version: 1.0.10

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down

0 comments on commit cbbc2fb

Please sign in to comment.