Open alexvoina opened 3 months ago
You can use Future.wait
to wait for multiple futures at the same time.
i've seen the example with Future.wait on the readers mapped into the ReaderInfo objects, which then require a fair amount of code & extensions to get the value. Is all of this necessary?
All I want to do, is to get the file paths into a List, before the call to print("finished..")
No. That code shows detailed information about the underlying dropped data to the user. That's not a common use-case. It does a lot more than you need.
thanks for the quick replies. I got it working as i want like this:
extension _ReadValue on DataReader {
Future<T?> readValue<T extends Object>(ValueFormat<T> format) {
final c = Completer<T?>();
final progress = getValue<T>(format, (value) {
c.complete(value);
}, onError: (e) {
c.completeError(e);
});
if (progress == null) {
c.complete(null);
}
return c.future;
}
}
onPerformDrop: (event) async {
final List<Uri?> fileUris = await Future.wait(event.session.items
.map((e) => e.dataReader!.readValue(Formats.fileUri)));
fileUris.where((e) => e != null).forEach((uri) => print(uri));
print("finished..");
}
Did i get it right, or is there an easier way?
Hi!
I want to use super_drag_and_drop for a fairly simple use case: dropping a list of files ,or more precisely, file paths into a DropRegion.
how can I await for getting the file paths of all the files dropped in the session?