tryFromItem static method
Returns null when the stored data is incomplete or out of range.
Implementation
static PaperFormat? tryFromItem(PrintStoreItem item) {
final data = item.data;
final feed = PaperFeed.values
.where((value) => value.name == data['feed'])
.firstOrNull;
double number(String key) => (data[key] as num?)?.toDouble() ?? 0;
int count(String key) => (data[key] as num?)?.toInt() ?? 0;
if (feed == null) return null;
final format = PaperFormat(
id: item.id,
name: item.name,
feed: feed,
pageWidthMm: number('page_width_mm'),
pageHeightMm: number('page_height_mm'),
columns: feed == PaperFeed.roll ? 1 : count('columns'),
rows: feed == PaperFeed.roll ? 1 : count('rows'),
cellWidthMm: number('cell_width_mm'),
cellHeightMm: number('cell_height_mm'),
marginTopMm: number('margin_top_mm'),
marginLeftMm: number('margin_left_mm'),
gapXMm: number('gap_x_mm'),
gapYMm: number('gap_y_mm'),
);
return format.validationError == null ? format : null;
}