tryFromItem static method
Returns null when the stored entry cannot be read, so a corrupted or future entry is skipped instead of breaking the template list.
Implementation
static PrintTemplate? tryFromItem(PrintStoreItem item) {
final data = item.data;
final design = data['design'];
if (design is! Map) return null;
try {
return PrintTemplate(
id: item.id,
name: item.name,
categoryId: data['category_id']?.toString(),
paperFormatId: data['paper_format']?.toString() ?? '',
design: ReportTemplate.fromJson(Map<String, dynamic>.from(design)),
settings: {
for (final entry in data.entries)
if (!_ownKeys.contains(entry.key)) entry.key: entry.value,
},
);
} catch (_) {
return null;
}
}