map<TResult extends Object?> method

  1. @optionalTypeArgs
TResult map<TResult extends Object?>({
  1. required TResult fill(
    1. BackgroundTypeFill value
    ),
  2. required TResult wallpaper(
    1. BackgroundTypeWallpaper value
    ),
  3. required TResult pattern(
    1. BackgroundTypePattern value
    ),
  4. required TResult chatTheme(
    1. BackgroundTypeChatTheme value
    ),
})

A switch-like method, using callbacks.

Callbacks receives the raw object, upcasted. It is equivalent to doing:

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

Implementation

@optionalTypeArgs
TResult map<TResult extends Object?>({
  required TResult Function(BackgroundTypeFill value) fill,
  required TResult Function(BackgroundTypeWallpaper value) wallpaper,
  required TResult Function(BackgroundTypePattern value) pattern,
  required TResult Function(BackgroundTypeChatTheme value) chatTheme,
}) {
  final _that = this;
  switch (_that) {
    case BackgroundTypeFill():
      return fill(_that);
    case BackgroundTypeWallpaper():
      return wallpaper(_that);
    case BackgroundTypePattern():
      return pattern(_that);
    case BackgroundTypeChatTheme():
      return chatTheme(_that);
  }
}