fromValue static method

MessageData? fromValue(
  1. Object? value
)

A static factory method that initializes MessageData with given value and asserts from input type.

Implementation

static MessageData<dynamic>? fromValue(Object? value) {
  if (value == null) {
    return null;
  }
  assert(
    value is MessageData ||
        value is Map ||
        value is List ||
        value is String ||
        value is Uint8List,
    'Message data must be either `Map`, `List`, `String` or `Uint8List`.'
    ' Does not support $value ("${value.runtimeType}")',
  );
  if (value is MessageData) {
    return value;
  } else if (value is Map) {
    return MessageData<Map<dynamic, dynamic>>(value);
  } else if (value is Uint8List) {
    return MessageData<Uint8List>(value);
  } else if (value is List) {
    return MessageData<List<dynamic>>(value);
  } else if (value is String) {
    return MessageData<String>(value);
  } else {
    throw AssertionError(
      'Message data must be either `Map`, `List`, `String` or `Uint8List`.'
      ' Does not support $value ("${value.runtimeType}")',
    );
  }
}