diff --git a/core/lib/utils/file_utils.dart b/core/lib/utils/file_utils.dart new file mode 100644 index 000000000..47f2cc67f --- /dev/null +++ b/core/lib/utils/file_utils.dart @@ -0,0 +1,77 @@ +import 'dart:developer'; +import 'dart:io'; +import 'package:core/domain/exceptions/download_file_exception.dart'; +import 'package:core/utils/build_utils.dart'; +import 'package:path_provider/path_provider.dart'; + +class FileUtils { + + static Future _getInternalStorageDirPath( + String nameFile, + { + String? folderPath, + String? extensionFile + } + ) async { + if (!BuildUtils.isWeb) { + String fileDirectory = (await getApplicationDocumentsDirectory()).absolute.path; + + + if (folderPath != null) { + fileDirectory = '$fileDirectory.$folderPath'; + } + + fileDirectory = '$fileDirectory.$nameFile'; + + if (extensionFile != null) { + fileDirectory = '$fileDirectory.$extensionFile'; + } + return fileDirectory; + } else { + throw DeviceNotSupportedException(); + } + } + + static Future saveToFile( + String nameFile, + String content, + { + String? folderPath, + String? extensionFile + }) async { + + final internalStorageDirPath = await _getInternalStorageDirPath( + nameFile, + folderPath: folderPath, + extensionFile: extensionFile + ); + + final file = File('$internalStorageDirPath.txt'); + log("FileUtils()::saveToFile: $file"); + + return await file.writeAsString(content, mode: FileMode.append); + } + + static Future getFromFile( + String nameFile, + { + String? folderPath, + String? extensionFile + } + ) async { + String emailContent = ''; + + final internalStorageDirPath = await _getInternalStorageDirPath( + nameFile, + folderPath: folderPath, + extensionFile: extensionFile + ); + + final file = File('$internalStorageDirPath.txt'); + emailContent = await file.readAsString(); + + log("FileUtils()::getFromFile: $emailContent"); + + return emailContent; + } +} \ No newline at end of file diff --git a/core/pubspec.lock b/core/pubspec.lock index cabc504d6..6cc89c3d3 100644 --- a/core/pubspec.lock +++ b/core/pubspec.lock @@ -121,6 +121,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.5" + external_path: + dependency: "direct main" + description: + name: external_path + sha256: "2095c626fbbefe70d5a4afc9b1137172a68ee2c276e51c3c1283394485bea8f4" + url: "https://pub.dev" + source: hosted + version: "1.0.3" fake_async: dependency: transitive description: @@ -352,6 +360,54 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + path_provider: + dependency: "direct main" + description: + name: path_provider + sha256: "04890b994ee89bfa80bf3080bfec40d5a92c5c7a785ebb02c13084a099d2b6f9" + url: "https://pub.dev" + source: hosted + version: "2.0.13" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: "2cec049d282c7f13c594b4a73976b0b4f2d7a1838a6dd5aaf7bd9719196bee86" + url: "https://pub.dev" + source: hosted + version: "2.0.27" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: ad4c4d011830462633f03eb34445a45345673dfd4faf1ab0b4735fbd93b19183 + url: "https://pub.dev" + source: hosted + version: "2.2.2" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: "2ae08f2216225427e64ad224a24354221c2c7907e448e6e0e8b57b1eb9f10ad1" + url: "https://pub.dev" + source: hosted + version: "2.1.10" + path_provider_platform_interface: + dependency: "direct main" + description: + name: path_provider_platform_interface + sha256: c2af5a8a6369992d915f8933dfc23172071001359d17896e83db8be57db8a397 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: d3f80b32e83ec208ac95253e0cd4d298e104fbc63cb29c5c69edaed43b0c69d6 + url: "https://pub.dev" + source: hosted + version: "2.1.6" petitparser: dependency: transitive description: @@ -360,14 +416,22 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.0" - plugin_platform_interface: + platform: dependency: transitive description: - name: plugin_platform_interface - sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" + name: platform + sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76" url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "3.1.0" + plugin_platform_interface: + dependency: "direct dev" + description: + name: plugin_platform_interface + sha256: c384b19bf8d317b3d1576327203cdc95f96bf5f109ab63ab72690fe32fdb0d3c + url: "https://pub.dev" + source: hosted + version: "2.1.0" pointer_interceptor: dependency: "direct main" description: @@ -376,6 +440,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.9.1" + process: + dependency: transitive + description: + name: process + sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" + url: "https://pub.dev" + source: hosted + version: "4.2.4" sky_engine: dependency: transitive description: flutter @@ -557,6 +629,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1 + url: "https://pub.dev" + source: hosted + version: "1.0.0" xml: dependency: transitive description: diff --git a/core/pubspec.yaml b/core/pubspec.yaml index 5b9420648..7c8c8c57e 100644 --- a/core/pubspec.yaml +++ b/core/pubspec.yaml @@ -63,6 +63,12 @@ dependencies: http_parser: 4.0.2 + path_provider: 2.0.13 + + external_path: 1.0.3 + + path_provider_platform_interface: 2.0.1 + # flutter_test from sdk depends on collection 1.17.0 collection: 1.17.0 @@ -71,6 +77,8 @@ dev_dependencies: sdk: flutter flutter_lints: 2.0.1 + + plugin_platform_interface: 2.1.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec