decode method

RTMPBroadcastRequestQualityEnum? decode(
  1. dynamic data, {
  2. bool allowNull = true,
})

Decodes a data to a RTMPBroadcastRequestQualityEnum.

If allowNull is true and the data cannot be decoded successfully, then null is returned. However, if allowNull is false and the data cannot be decoded successfully, then an UnimplementedError is thrown.

The allowNull is very handy when an API changes and a new enum value is added or removed, and users are still using an old app with the old code.

Implementation

RTMPBroadcastRequestQualityEnum? decode(dynamic data, {bool allowNull = true}) {
  if (data != null) {
    switch (data) {
      case r'360p': return RTMPBroadcastRequestQualityEnum.n360p;
      case r'480p': return RTMPBroadcastRequestQualityEnum.n480p;
      case r'720p': return RTMPBroadcastRequestQualityEnum.n720p;
      case r'1080p': return RTMPBroadcastRequestQualityEnum.n1080p;
      case r'1440p': return RTMPBroadcastRequestQualityEnum.n1440p;
      case r'portrait-360x640': return RTMPBroadcastRequestQualityEnum.portrait360x640;
      case r'portrait-480x854': return RTMPBroadcastRequestQualityEnum.portrait480x854;
      case r'portrait-720x1280': return RTMPBroadcastRequestQualityEnum.portrait720x1280;
      case r'portrait-1080x1920': return RTMPBroadcastRequestQualityEnum.portrait1080x1920;
      case r'portrait-1440x2560': return RTMPBroadcastRequestQualityEnum.portrait1440x2560;
      default:
        if (!allowNull) {
          throw ArgumentError('Unknown enum value to decode: $data');
        }
    }
  }
  return null;
}