getValue<T extends Object> method

  1. @override
ReadProgress? getValue<T extends Object>(
  1. ValueFormat<T> format,
  2. AsyncValueChanged<T?> onValue, {
  3. ValueChanged<Object>? onError,
})
override

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;
  }
}