From 962102407dff662ad25b55a5f7d7333f36c075aa Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 24 Aug 2023 22:08:27 +0200 Subject: [PATCH] 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 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 --- .../dynamite/lib/src/openapi_builder.dart | 2 +- .../neon/neon/lib/src/pages/settings.dart | 2 +- .../nextcloud/lib/src/api/notes.openapi.dart | 5 +-- packages/nextcloud/lib/src/webdav/client.dart | 40 ++++++++----------- packages/nextcloud/test/webdav_test.dart | 10 ++--- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index d41ea1f2b73..51780b65ce0 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/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('}'); diff --git a/packages/neon/neon/lib/src/pages/settings.dart b/packages/neon/neon/lib/src/pages/settings.dart index 8baf90f71c1..6e35939168a 100644 --- a/packages/neon/neon/lib/src/pages/settings.dart +++ b/packages/neon/neon/lib/src/pages/settings.dart @@ -260,7 +260,7 @@ class _SettingsPageState extends State { ), ), ); - 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()); diff --git a/packages/nextcloud/lib/src/api/notes.openapi.dart b/packages/nextcloud/lib/src/api/notes.openapi.dart index 2945461ab52..6fbd34cda5a 100644 --- a/packages/nextcloud/lib/src/api/notes.openapi.dart +++ b/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(), diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 88a10b53dff..9f98a9661fe 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/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); diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index bf6ac30b50c..b9080ccbfd2 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/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);