contentParts property

List<Map<String, dynamic>> get contentParts

Convenience view of content as a list of content-part maps.

If content is a String, returns [{'type': 'text', 'text': content}]; if it is a List, returns it cast to List<Map<String, dynamic>>; otherwise an empty list. content itself stays Object so both the string and the part-list wire shapes pass through verbatim.

Implementation

List<Map<String, dynamic>> get contentParts {
  final c = content;
  if (c is String) {
    return <Map<String, dynamic>>[
      {'type': 'text', 'text': c},
    ];
  }
  if (c is List) {
    return c.whereType<Map<String, dynamic>>().toList();
  }
  return const <Map<String, dynamic>>[];
}