Select Git revision
-
Benoît Harrault authoredBenoît Harrault authored
picture_storage.dart 944 B
import 'dart:io';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:random/utils/tools.dart';
class PictureStorage {
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<String> _localFilePath(String name) async {
final path = await _localPath;
return '$path/$name';
}
Future<File> moveFile(File sourceFile, String newPath) async {
try {
return await sourceFile.rename(newPath);
} on FileSystemException catch (e) {
printlog('Found exception while moving file: $e');
final newFile = await sourceFile.copy(newPath);
await sourceFile.delete();
return newFile;
}
}
Future<File> writeCounter(File sourceFile) async {
final targetFile = await _localFilePath(basename(sourceFile.path));
return moveFile(sourceFile, targetFile);
}
}