From 7bd6e71dafad52d84f26ad9d4c4d6d7d6e8471c4 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Wed, 4 Oct 2023 09:11:17 -0300 Subject: [PATCH] fix lint rules --- lib/src/cache_storage.dart | 10 ++-- lib/src/utils/path_utils.dart | 4 +- lib/src/web/web_io.dart | 8 +-- pubspec.yaml | 1 + test/src/io_folder_test.dart | 104 ---------------------------------- 5 files changed, 12 insertions(+), 115 deletions(-) diff --git a/lib/src/cache_storage.dart b/lib/src/cache_storage.dart index 08f8280..b4bdd79 100644 --- a/lib/src/cache_storage.dart +++ b/lib/src/cache_storage.dart @@ -10,11 +10,11 @@ class IOCacheStorage { debugPrint('saving file on local storage'); - final _file = File('${cacheDir.path}/${entity.name}'); + final file = File('${cacheDir.path}/${entity.name}'); final readStream = File(entity.path).openRead(); - final writeStream = await _file.open(mode: FileMode.write); + final writeStream = await file.open(mode: FileMode.write); await for (List chunk in readStream) { await writeStream.writeFrom(chunk); @@ -22,7 +22,7 @@ class IOCacheStorage { await writeStream.close(); - return _file.path; + return file.path; } Future getFileFromStorage(String fileName) async { @@ -32,9 +32,9 @@ class IOCacheStorage { final cacheDir = await _getCacheDir(); - final _file = File('${cacheDir.path}/$fileName'); + final file = File('${cacheDir.path}/$fileName'); - return adapter.fromFile(_file); + return adapter.fromFile(file); } Future freeLocalStorage() async { diff --git a/lib/src/utils/path_utils.dart b/lib/src/utils/path_utils.dart index 4a9e904..8cbca4c 100644 --- a/lib/src/utils/path_utils.dart +++ b/lib/src/utils/path_utils.dart @@ -51,7 +51,7 @@ Future getDefaultMobileDownloadDir() async { Future getDefaultAppDir() { return path_provider .getApplicationDocumentsDirectory() - .then((value) => value.path + '/'); + .then((value) => '${value.path}/'); } /// Returns the file extension from the file `name`, when having, in other case the extension @@ -90,7 +90,7 @@ String getFileExtension({ Future _getDefaultIOSDir() async { final iosDirectory = await path_provider.getApplicationDocumentsDirectory(); - final iosDownloadsDirectory = Directory(iosDirectory.path + '/Downloads/'); + final iosDownloadsDirectory = Directory('${iosDirectory.path}/Downloads/'); if (!iosDownloadsDirectory.existsSync()) { iosDownloadsDirectory.createSync(); diff --git a/lib/src/web/web_io.dart b/lib/src/web/web_io.dart index 452a8bc..342595a 100644 --- a/lib/src/web/web_io.dart +++ b/lib/src/web/web_io.dart @@ -145,11 +145,11 @@ class WebFileSystemProvider implements MultiFileProvider { class FolderPicker { Future pickFolderFiles( Function(Stream> stream) getFiles) async { - StreamController> _folderController = + StreamController> folderController = StreamController>(); /// Set the stream to get the files - getFiles(_folderController.stream); + getFiles(folderController.stream); final folderInput = FileUploadInputElement(); @@ -167,10 +167,10 @@ class FolderPicker { /// To avoid the `IOFileAdapter` imports dart:html, this file will be mounted /// here. - _folderController.add(files.map((e) => _mountFile(e)).toList()); + folderController.add(files.map((e) => _mountFile(e)).toList()); /// Closes to finish the stream with all files - _folderController.close(); + folderController.close(); folderInput.removeAttribute('webkitdirectory'); folderInput.remove(); }); diff --git a/pubspec.yaml b/pubspec.yaml index 29f7f40..6545d7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: ref: fix-extension device_info_plus: ^9.0.3 async: ^2.9.0 + path: ^1.8.3 dev_dependencies: flutter_test: sdk: flutter diff --git a/test/src/io_folder_test.dart b/test/src/io_folder_test.dart index af3a8cb..ba8fa6d 100644 --- a/test/src/io_folder_test.dart +++ b/test/src/io_folder_test.dart @@ -1,6 +1,4 @@ -import 'dart:async'; import 'dart:io'; -import 'dart:typed_data'; import 'package:ardrive_io/ardrive_io.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -83,107 +81,5 @@ void main() { expect(files2stLevel.length, 2); expect(folders2stLevel.isEmpty, true); }); - - test( - 'fromFileSystemDirectory method should return the folder hierachy correctly', - () async { - // TODO: implement test - // ignore: unused_local_variable - final files = [ - _TestFile('first-level/file.xpto'), - _TestFile('first-level/subdirectory-level/subdirectory-file'), - _TestFile('first-level/subdirectory-level/subdirectory-file-1.xpto'), - _TestFile('first-level/subdirectory-level/subdirectory-file-2.xpto'), - _TestFile( - 'first-level/subdirectory-level/subdirectory-level2/subdirectory-file-3.xpto'), - ]; - - // await sut.fromFileSystemDirectory(firstLevelDirectory); - - // final firstLevelContent = await firstLevelFolder.listContent(); - - // expect(firstLevelFolder.name, 'first-level'); - // expect(firstLevelFolder.path, 'first-level'); - // expect(firstLevelFolder.lastModifiedDate, - // firstLevelDirectory.statSync().modified); - - // /// First level folder content - // /// first-level/ - // /// first-level-file.xpto - // /// subdirectory-level/ - // expect(firstLevelContent.whereType().length, 1); - // expect(firstLevelContent.whereType().length, 1); - - // /// subdirectory-level/ - // /// subdirectory-file - // /// subdirectory-file-1.xpto - // final secondLevelFolder = firstLevelContent.whereType().first; - // expect(secondLevelFolder.name, 'subdirectory-level'); - // expect(secondLevelFolder.path, secondLevelDirectory.path); - // expect(secondLevelFolder.lastModifiedDate, - // secondLevelDirectory.statSync().modified); - - // /// get the second level and verify its content - // final secondLevelContent = await secondLevelFolder.listContent(); - // expect(secondLevelContent.whereType().length, 2); - // expect(secondLevelContent.whereType().length, 0); - - // /// Test if `listFiles()` and `listSubfolders()` were mounted correctly - // final files1stLevel = await firstLevelFolder.listFiles(); - // final folders1stLevel = await firstLevelFolder.listSubfolders(); - // final files2stLevel = await secondLevelFolder.listFiles(); - // final folders2stLevel = await secondLevelFolder.listSubfolders(); - - // /// See the folder structure - // expect(files1stLevel.length, 3); - // expect(folders1stLevel.length, 1); - // expect(files2stLevel.length, 2); - // expect(folders2stLevel.isEmpty, true); - }); }); } - -class _TestFile extends MutableIOFilePath { - _TestFile(this.virtualPath); - - @override - String virtualPath = ''; - - @override - // TODO: implement contentType - String get contentType => throw UnimplementedError(); - - @override - // TODO: implement lastModifiedDate - DateTime get lastModifiedDate => throw UnimplementedError(); - - @override - // TODO: implement length - FutureOr get length => throw UnimplementedError(); - - @override - // TODO: implement name - String get name => throw UnimplementedError(); - - @override - Stream openReadStream([int start = 0, int? end]) { - // TODO: implement openReadStream - throw UnimplementedError(); - } - - @override - // TODO: implement path - String get path => throw UnimplementedError(); - - @override - Future readAsBytes() { - // TODO: implement readAsBytes - throw UnimplementedError(); - } - - @override - Future readAsString() { - // TODO: implement readAsString - throw UnimplementedError(); - } -}