moveTo method
move the file to destination and return the new file.
the first move of a temp file is a cheap rename,
later calls copy, so the file can be stored in many places.
File saved = await file.moveTo('/data/avatars/1.png');
Implementation
Future<File> moveTo(String destination) async {
File target = File(destination);
await target.parent.create(recursive: true);
Uint8List? memory = _bytes;
if (memory != null) {
return target.writeAsBytes(memory);
}
File source = _file!;
if (!_isTemp) return source.copy(destination);
try {
_file = await source.rename(destination);
} on FileSystemException {
/// rename does not work across disks (eg. /tmp and a docker volume)
_file = await source.copy(destination);
await source.delete();
}
_isTemp = false;
return _file!;
}