getRequiredPropOrNull<V> method

V? getRequiredPropOrNull<V>(
  1. V accessProp(
    1. T spiedView
    )
)

Returns the value of the prop read within accessProp if it's specified, or null otherwise.

Useful for safely accessing required props in a "partial" props map that may not contain them.

See also: getRequiredProp.

For example:

class FooProps on UiProps {
  late String requiredProp;
}

void example(FooProps props) {
  // Unsafe: this will throw if requiredProp is not specified
  final requiredProp = props.requiredProp;

  final requiredPropOrNull =
      props.getRequiredPropOrNull((p) => p.requiredProp);
}

Implementation

V? getRequiredPropOrNull<V>(V Function(T spiedView) accessProp) =>
    getRequiredProp(accessProp, orElse: () => null);