Skip to content

Commit

Permalink
refactor(dynamite,neon,nextcloud): use dart 3.1 utf8.encode as Uint8List
Browse files Browse the repository at this point in the history
While the entire utf8 converter has been switched to Uint8List the type annotation still remains List<int> for this release.
Adding the downcast as this behavior is what we need.

A future dart release should also change the type annotations triggering a linter rule.
see: dart-lang/sdk#52801
Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
  • Loading branch information
Leptopoda committed Aug 24, 2023
1 parent 86bb58d commit 9621024
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/dynamite/dynamite/lib/src/openapi_builder.dart
Expand Up @@ -541,7 +541,7 @@ class OpenAPIBuilder implements Builder {
code.write('if ($parameterName != null) {');
}
code.write(
'_body = Uint8List.fromList(utf8.encode(${result.encode(parameterName, mimeType: mimeType)}));',
'_body = utf8.encode(${result.encode(parameterName, mimeType: mimeType)}) as Uint8List;',
);
if (dartParameterNullable) {
code.write('}');
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/pages/settings.dart
Expand Up @@ -260,7 +260,7 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
);
await saveFileWithPickDialog(fileName, Uint8List.fromList(utf8.encode(data)));
await saveFileWithPickDialog(fileName, utf8.encode(data) as Uint8List);
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());
Expand Down
5 changes: 2 additions & 3 deletions packages/nextcloud/lib/src/api/notes.openapi.dart
Expand Up @@ -336,9 +336,8 @@ class NotesClient extends DynamiteClient {
}
// coverage:ignore-end
headers['Content-Type'] = 'application/json';
body = Uint8List.fromList(
utf8.encode(json.encode(_jsonSerializers.serialize(settings, specifiedType: const FullType(NotesSettings)))),
);
body = utf8.encode(json.encode(_jsonSerializers.serialize(settings, specifiedType: const FullType(NotesSettings))))
as Uint8List;
final response = await doRequest(
'put',
Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(),
Expand Down
40 changes: 17 additions & 23 deletions packages/nextcloud/lib/src/webdav/client.dart
Expand Up @@ -247,13 +247,11 @@ class WebDavClient {
'PROPFIND',
_constructPath(path),
data: Stream.value(
Uint8List.fromList(
utf8.encode(
WebDavPropfind(prop: prop ?? WebDavPropWithoutValues())
.toXmlElement(namespaces: namespaces)
.toXmlString(),
),
),
utf8.encode(
WebDavPropfind(prop: prop ?? WebDavPropWithoutValues())
.toXmlElement(namespaces: namespaces)
.toXmlString(),
) as Uint8List,
),
headers: {
if (depth != null) ...{
Expand All @@ -277,14 +275,12 @@ class WebDavClient {
'REPORT',
_constructPath(path),
data: Stream.value(
Uint8List.fromList(
utf8.encode(
WebDavOcFilterFiles(
filterRules: filterRules,
prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line
).toXmlElement(namespaces: namespaces).toXmlString(),
),
),
utf8.encode(
WebDavOcFilterFiles(
filterRules: filterRules,
prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line
).toXmlElement(namespaces: namespaces).toXmlString(),
) as Uint8List,
),
),
);
Expand All @@ -304,14 +300,12 @@ class WebDavClient {
'PROPPATCH',
_constructPath(path),
data: Stream.value(
Uint8List.fromList(
utf8.encode(
WebDavPropertyupdate(
set: set != null ? WebDavSet(prop: set) : null,
remove: remove != null ? WebDavRemove(prop: remove) : null,
).toXmlElement(namespaces: namespaces).toXmlString(),
),
),
utf8.encode(
WebDavPropertyupdate(
set: set != null ? WebDavSet(prop: set) : null,
remove: remove != null ? WebDavRemove(prop: remove) : null,
).toXmlElement(namespaces: namespaces).toXmlString(),
) as Uint8List,
),
);
final data = await _parseResponse(response);
Expand Down
10 changes: 5 additions & 5 deletions packages/nextcloud/test/webdav_test.dart
Expand Up @@ -137,7 +137,7 @@ void main() {
});

test('Get directory props', () async {
final data = Uint8List.fromList(utf8.encode('test'));
final data = utf8.encode('test') as Uint8List;
await client.webdav.mkcol('test');
await client.webdav.put(data, 'test/test.txt');

Expand Down Expand Up @@ -169,7 +169,7 @@ void main() {
});

test('Filter files', () async {
final response = await client.webdav.put(Uint8List.fromList(utf8.encode('test')), 'test.txt');
final response = await client.webdav.put(utf8.encode('test') as Uint8List, 'test.txt');
final id = response.headers['oc-fileid']!.first;
await client.webdav.proppatch(
'test.txt',
Expand Down Expand Up @@ -202,7 +202,7 @@ void main() {
final uploadTime = DateTime.now();

await client.webdav.put(
Uint8List.fromList(utf8.encode('test')),
utf8.encode('test') as Uint8List,
'test.txt',
lastModified: lastModifiedDate,
created: createdDate,
Expand Down Expand Up @@ -237,7 +237,7 @@ void main() {
});

test('Remove properties', () async {
await client.webdav.put(Uint8List.fromList(utf8.encode('test')), 'test.txt');
await client.webdav.put(utf8.encode('test') as Uint8List, 'test.txt');

var updated = await client.webdav.proppatch(
'test.txt',
Expand Down Expand Up @@ -323,7 +323,7 @@ void main() {
('put_get_utf8_segment', 'res-%e2%82%ac'),
]) {
test(name, () async {
final content = Uint8List.fromList(utf8.encode('This is a test file'));
final content = utf8.encode('This is a test file') as Uint8List;

final response = await client.webdav.put(content, path);
expect(response.statusCode, 201);
Expand Down

0 comments on commit 9621024

Please sign in to comment.