In my application user can copy local file:
- user clicks button “copy file”.
- file copying starts.
- user clicks button “cancel copying file” (before file copy done).
I can use CancelableOperation to cancel Future (File.copy), but in this case copy of file is creating even if user canceled the Future.
So I have to delete it myself.
Is it possible to cancel file copying without deleting a copy of file?
This is code:
import 'package:async/async.dart';
...
CancelableOperation? fileCopyingOperation;
...
// user clicks "copy file"
fileCopyingOperation = CancelableOperation.fromFuture(
File(filePath).copy(filePathNew),
onCancel: () {},
);
...
// user clicks "cancel copying file"
fileCopyingOperation?.cancel();