fromMap static method

VAPContent fromMap(
  1. Map<String, dynamic> value
)

Creates a VAPContent instance from a map received from native platforms.

This factory method automatically determines the appropriate subclass based on the content type and value in the map.

Parameters:

  • value: Map containing 'contentType' and 'contentValue' keys

Returns the appropriate VAPContent subclass instance. Throws ArgumentError if the content type is unknown.

Implementation

static VAPContent fromMap(Map<String, dynamic> value) {
  final contentType = value['contentType'] as String;
  final contentValue = value['contentValue'] as String;

  switch (contentType) {
    case 'text':
      return TextContent(contentValue);
    case 'image':
      if (contentValue.startsWith('http://') ||
          contentValue.startsWith('https://')) {
        return ImageURLContent(contentValue);
      } else if (contentValue.startsWith('data:image/')) {
        return ImageBase64Content(contentValue);
      } else if (contentValue.startsWith('assets/')) {
        return ImageAssetContent(contentValue);
      } else {
        return ImageFileContent(contentValue);
      }
    default:
      throw ArgumentError('Unknown content type: $contentType');
  }
}