mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? permissionNotGranted(
    1. _permissionNotGranted value
    )?,
  2. TResult? bluetoothNotSupported(
    1. _bluetoothNotSupported value
    )?,
  3. TResult? scanningError(
    1. _scanningError value
    )?,
  4. TResult? authenticationError(
    1. _authenticationError value
    )?,
  5. TResult? stateError(
    1. _stateError value
    )?,
  6. TResult? measurmentError(
    1. _measurmentError value
    )?,
  7. TResult? connectionError(
    1. _connectionError value
    )?,
  8. TResult? startMeasurementError(
    1. _startMeasurementError value
    )?,
  9. TResult? stopMeasurementError(
    1. _stopMeasurementError value
    )?,
  10. TResult? fetchMeasurementError(
    1. _fetchMeasurementError value
    )?,
  11. TResult? stopFetchMeasurementError(
    1. _stopFetchMeasurementError value
    )?,
  12. TResult? identifyBlinkError(
    1. _identifyBlinkError value
    )?,
  13. TResult? dfuBootloaderError(
    1. _dfuBootloaderError value
    )?,
  14. TResult? commandError(
    1. _commandError value
    )?,
})

A variant of map that fallback to returning null.

It is equivalent to doing:

switch (sealedClass) {
  case final Subclass value:
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( _permissionNotGranted value)?  permissionNotGranted,TResult? Function( _bluetoothNotSupported value)?  bluetoothNotSupported,TResult? Function( _scanningError value)?  scanningError,TResult? Function( _authenticationError value)?  authenticationError,TResult? Function( _stateError value)?  stateError,TResult? Function( _measurmentError value)?  measurmentError,TResult? Function( _connectionError value)?  connectionError,TResult? Function( _startMeasurementError value)?  startMeasurementError,TResult? Function( _stopMeasurementError value)?  stopMeasurementError,TResult? Function( _fetchMeasurementError value)?  fetchMeasurementError,TResult? Function( _stopFetchMeasurementError value)?  stopFetchMeasurementError,TResult? Function( _identifyBlinkError value)?  identifyBlinkError,TResult? Function( _dfuBootloaderError value)?  dfuBootloaderError,TResult? Function( _commandError value)?  commandError,}){
final _that = this;
switch (_that) {
case _permissionNotGranted() when permissionNotGranted != null:
return permissionNotGranted(_that);case _bluetoothNotSupported() when bluetoothNotSupported != null:
return bluetoothNotSupported(_that);case _scanningError() when scanningError != null:
return scanningError(_that);case _authenticationError() when authenticationError != null:
return authenticationError(_that);case _stateError() when stateError != null:
return stateError(_that);case _measurmentError() when measurmentError != null:
return measurmentError(_that);case _connectionError() when connectionError != null:
return connectionError(_that);case _startMeasurementError() when startMeasurementError != null:
return startMeasurementError(_that);case _stopMeasurementError() when stopMeasurementError != null:
return stopMeasurementError(_that);case _fetchMeasurementError() when fetchMeasurementError != null:
return fetchMeasurementError(_that);case _stopFetchMeasurementError() when stopFetchMeasurementError != null:
return stopFetchMeasurementError(_that);case _identifyBlinkError() when identifyBlinkError != null:
return identifyBlinkError(_that);case _dfuBootloaderError() when dfuBootloaderError != null:
return dfuBootloaderError(_that);case _commandError() when commandError != null:
return commandError(_that);case _:
  return null;

}
}