ChatMessage.fromJson constructor
ChatMessage.fromJson(
- Map<String, dynamic> json
)
Implementation
factory ChatMessage.fromJson(Map<String, dynamic> json) {
return ChatMessage(
message: json['message'] as String? ?? '',
isUser: json['isUser'] as bool? ?? false,
isWaiting: json['isWaiting'] as bool? ?? false,
timestamp: json['timestamp'] != null
? DateTime.tryParse(json['timestamp'] as String? ?? '')
: null,
type: json['type'] as String? ?? 'content',
threadId: json['threadId'] as String?,
// Ensure citations are List<Map<String, dynamic>>
citations: (json['citations'] as List<dynamic>?)
?.map((item) => Map<String, dynamic>.from(item as Map))
.toList(),
);
}