orDefault method

  1. @useResult
T orDefault(
  1. T defaultValue
)

Returns this value if non-null, otherwise defaultValue.

A typed shorthand for value ?? defaultValue that reads clearly in chains.

Example:

String? name;
name.orDefault('Anonymous'); // 'Anonymous'

Implementation

@useResult
T orDefault(T defaultValue) => this ?? defaultValue;