when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String? id,
- String name,
- MapSource source,
- String? rasterServerLight,
- String? rasterServerDark,
- String? googleToken,
- List<
GoogleMapLayer> ? googleLayers, - String? mapboxToken,
- List<
MapboxStyle> ? mapboxLayers, - String? mapboxCustomUsername,
- String? mapboxCustomStyleId,
- String? hereToken,
- List<
HereStyle> ? hereLayers, - String attributionUrl,
- String? attributionUrlDark,
- double attributionWidth,
- double attributionHeight,
- List<
String> appsIds,
A switch-like method, using callbacks.
As opposed to map, this offers destructuring.
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case Subclass2(:final field2):
return ...;
}
Implementation
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String? id, String name, @JsonKey(unknownEnumValue: MapSource.custom) MapSource source, String? rasterServerLight, String? rasterServerDark, String? googleToken, @JsonKey(unknownEnumValue: GoogleMapLayer.roadmap) List<GoogleMapLayer>? googleLayers, String? mapboxToken, @JsonKey(unknownEnumValue: MapboxStyle.navigation) List<MapboxStyle>? mapboxLayers, String? mapboxCustomUsername, String? mapboxCustomStyleId, String? hereToken, @JsonKey(unknownEnumValue: HereStyle.lite) List<HereStyle>? hereLayers, String attributionUrl, String? attributionUrlDark, double attributionWidth, double attributionHeight, List<String> appsIds) $default,) {final _that = this;
switch (_that) {
case _MapLayerInput():
return $default(_that.id,_that.name,_that.source,_that.rasterServerLight,_that.rasterServerDark,_that.googleToken,_that.googleLayers,_that.mapboxToken,_that.mapboxLayers,_that.mapboxCustomUsername,_that.mapboxCustomStyleId,_that.hereToken,_that.hereLayers,_that.attributionUrl,_that.attributionUrlDark,_that.attributionWidth,_that.attributionHeight,_that.appsIds);case _:
throw StateError('Unexpected subclass');
}
}