maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. String? authority,
    2. String? serviceName,
    3. bool? multiMode,
    4. @JsonKey.new(name: 'idle_timeout') int? idleTimeout,
    5. @JsonKey.new(name: 'health_check_timeout') int? healthCheckTimeout,
    6. @JsonKey.new(name: 'permit_without_stream') bool? permitWithoutStream,
    7. @JsonKey.new(name: 'initial_windows_size') int? initialWindowsSize,
    8. @JsonKey.new(name: 'user_agent') String? userAgent,
    )?, {
  2. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  TResult Function(
          String? authority,
          String? serviceName,
          bool? multiMode,
          @JsonKey(name: 'idle_timeout') int? idleTimeout,
          @JsonKey(name: 'health_check_timeout') int? healthCheckTimeout,
          @JsonKey(name: 'permit_without_stream') bool? permitWithoutStream,
          @JsonKey(name: 'initial_windows_size') int? initialWindowsSize,
          @JsonKey(name: 'user_agent') String? userAgent)?
      $default, {
  required TResult orElse(),
}) {
  final _that = this;
  switch (_that) {
    case _GRPCConfig() when $default != null:
      return $default(
          _that.authority,
          _that.serviceName,
          _that.multiMode,
          _that.idleTimeout,
          _that.healthCheckTimeout,
          _that.permitWithoutStream,
          _that.initialWindowsSize,
          _that.userAgent);
    case _:
      return orElse();
  }
}