TF-1822: Store and get html string to file in internal storage mobile

(cherry picked from commit 50b8c7862a5c9b6cbd856fd63bf61d9973723429)
This commit is contained in:
HuyNguyen
2023-05-08 23:28:10 +07:00
committed by Dat Vu
parent f96cd43b95
commit be681cb7a7
3 changed files with 169 additions and 4 deletions
+77
View File
@@ -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<String> _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<File> 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<String> 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;
}
}
+84 -4
View File
@@ -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:
+8
View File
@@ -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