Browse Source

refactor(dynamite,neon,nextcloud): use dart 3.1 utf8.encode as Uint8List

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: https://github.com/dart-lang/sdk/issues/52801
Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/592/head
Nikolas Rimikis 1 year ago
parent
commit
962102407d
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 2
      packages/dynamite/dynamite/lib/src/openapi_builder.dart
  2. 2
      packages/neon/neon/lib/src/pages/settings.dart
  3. 5
      packages/nextcloud/lib/src/api/notes.openapi.dart
  4. 40
      packages/nextcloud/lib/src/webdav/client.dart
  5. 10
      packages/nextcloud/test/webdav_test.dart

2
packages/dynamite/dynamite/lib/src/openapi_builder.dart

@ -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('}');

2
packages/neon/neon/lib/src/pages/settings.dart

@ -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());

5
packages/nextcloud/lib/src/api/notes.openapi.dart

@ -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(),

40
packages/nextcloud/lib/src/webdav/client.dart

@ -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) ...{
@ -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,
),
),
);
@ -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);

10
packages/nextcloud/test/webdav_test.dart

@ -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');
@ -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',
@ -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,
@ -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',
@ -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);

Loading…
Cancel
Save