toOr<T> method

T toOr<T>(
  1. T defaultValue
)

Converts the wrapped value to type T, falling back to defaultValue on failure.

This is equivalent to calling tryTo and providing a default.

Implementation

T toOr<T>(T defaultValue) {
  try {
    final v = to<T>();
    return v;
  } on ConversionException {
    return defaultValue;
  }
}