DocumentSide.fromJson constructor
DocumentSide.fromJson(
- Map<String, dynamic> json
)
Implementation
factory DocumentSide.fromJson(Map<String, dynamic> json) {
// Android encodes a flat object with a "type" discriminator:
// { "type": "front", "id": ..., "videoId": ... }
final type = json['type'];
if (type is String) {
return DocumentSide(
side: DocumentSideType.fromJson(type),
id: json['id'] as String,
videoId: json['videoId'] as String?,
);
}
// iOS encodes the enum case as the wrapping key:
// { "front": { "id": ..., "videoId": ... } }
for (final key in const ['front', 'back']) {
final nested = json[key];
if (nested is Map<String, dynamic>) {
return DocumentSide(
side: DocumentSideType.fromJson(key),
id: nested['id'] as String,
videoId: nested['videoId'] as String?,
);
}
}
throw FormatException('Unrecognized DocumentSide shape: $json');
}