PostDocument.parse constructor

PostDocument.parse(
  1. String? raw
)

Aceita uma String JSON (lista de blocos). Vazio/ inválido → documento vazio.

Implementation

factory PostDocument.parse(String? raw) {
  if (raw == null || raw.trim().isEmpty) return const PostDocument([]);
  try {
    final decoded = jsonDecode(raw);
    if (decoded is List) return PostDocument.fromJson(decoded);
  } catch (_) {
    /* não é JSON de blocos */
  }
  return const PostDocument([]);
}