TF-3042 Create PublicAsset and display after pick image
This commit is contained in:
@@ -121,4 +121,18 @@ class FileUtils {
|
||||
final base64Data = base64Encode(Uint8List.view(buffer));
|
||||
return base64Data;
|
||||
}
|
||||
|
||||
Future<void> deleteCompressedFileOnMobile(String filePath, {required String pathContains}) async {
|
||||
log('$runtimeType::deleteCompressedFileOnMobile: filePath: $filePath');
|
||||
if (!PlatformInfo.isMobile) return;
|
||||
|
||||
try {
|
||||
final File file = File(filePath);
|
||||
if (await file.exists() && file.path.contains(pathContains)) {
|
||||
await file.delete();
|
||||
}
|
||||
} catch (e) {
|
||||
logError('$runtimeType::deleteCompressedFileOnMobile: error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:core/utils/file_utils.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
@@ -38,6 +39,41 @@ void main() {
|
||||
|
||||
file.delete();
|
||||
});
|
||||
|
||||
test(
|
||||
'Should delete file '
|
||||
'when deleteCompressedFileOnMobile is called '
|
||||
'and file exists '
|
||||
'and Platform is mobile',
|
||||
() async {
|
||||
// arrange
|
||||
final file = await FileUtils().saveToFile(nameFile: fileName, content: fileContent);
|
||||
|
||||
// act
|
||||
await FileUtils().deleteCompressedFileOnMobile(file.path, pathContains: fileName);
|
||||
|
||||
// assert
|
||||
expect(await file.exists(), equals(false));
|
||||
});
|
||||
|
||||
test(
|
||||
'Should not delete file '
|
||||
'when deleteCompressedFileOnMobile is called '
|
||||
'and file exists '
|
||||
'and Platform is not mobile',
|
||||
() async {
|
||||
// arrange
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
final file = await FileUtils().saveToFile(nameFile: fileName, content: fileContent);
|
||||
expect(await file.exists(), equals(true));
|
||||
|
||||
// act
|
||||
await FileUtils().deleteCompressedFileOnMobile(file.path, pathContains: fileName);
|
||||
|
||||
// assert
|
||||
expect(await file.exists(), equals(true));
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user