getValue<T extends Object> method
- ValueFormat<
T> format, - AsyncValueChanged<
T?> onValue, { - ValueChanged<
Object> ? onError,
Loads the value for the given format.
If no value for given format is available, null
progress is returned
and the onValue
block will not be called.
Getting the value is intentionally not exposed as async operation in order to prevent awaiting in contexts where it could block platform code (i.e. drop handle during drag and drop).
When reading value form clipboard you can use the async variant in ClipboardDataReader.
Note that it is possible to receive a null
value despite canProvide
returning true. Sometimes the presence of value can not be determined
just form the format string, but only from the data itself. For example
file and regular URI have same type on some platforms, so when receiving
Formats.fileUri the decoder will have to fetch the value and will return
null if URI is not a file uri.
Implementation
@override
ReadProgress? getValue<T extends Object>(
ValueFormat<T> format,
AsyncValueChanged<T?> onValue, {
ValueChanged<Object>? onError,
}) {
final item =
items.firstWhereOrNull((element) => element.canProvide(format));
if (item != null) {
return item.getValue(
format,
onValue,
onError: onError,
);
} else {
return null;
}
}