Answers for "move file to particular path flutter"

0

move file to particular path flutter

final sourceFile = await File('/storage/emulated/0/Myfolder/image.jpg');
final newFilePath = await File('/storage/emulated/0/NewFolder/image.jpg');

moveFile(sourceFile, newFilePath);

Future<File> moveFile(File sourceFile, String newPath) async {
  try {
    // prefer using rename as it is probably faster
    return await sourceFile.rename(newPath);
  } on FileSystemException catch (e) {
    // if rename fails, copy the source file and then delete it
    final newFile = await sourceFile.copy(newPath);
    await sourceFile.delete();
    return newFile;
  }
}
Posted by: Guest on March-04-2022

Browse Popular Code Answers by Language