Conversation.fromJson constructor
Creates a Conversation from a JSON representation.
The json
parameter should contain the required fields:
- 'id': String identifier
- 'title': String title
- 'messages': List of message objects
- 'createdAt': ISO 8601 formatted date string
- 'updatedAt': ISO 8601 formatted date string (optional)
Throws a FormatException if the JSON is malformed.
Implementation
factory Conversation.fromJson(Map<String, dynamic> json) => Conversation(
id: json['id'] as String,
title: json['title'] as String,
messages: (json['messages'] as List<dynamic>)
.map((msg) => ChatMessage.fromJson(
msg as Map<String, dynamic>,
))
.toList(),
createdAt: DateTime.parse(json['createdAt'] as String),
updatedAt: json['updatedAt'] != null
? DateTime.parse(json['updatedAt'] as String)
: null,
);