PrinterEvent.fromMap constructor

PrinterEvent.fromMap(
  1. Map map
)

Implementation

factory PrinterEvent.fromMap(Map<dynamic, dynamic> map) {
  final typeStr = (map['type'] as String?) ?? 'status';
  final type = PrinterEventType.values.firstWhere(
    (e) => e.name == typeStr,
    orElse: () => PrinterEventType.status,
  );

  final deviceVal = map['device'];
  final device = deviceVal is Map ? PrinterDevice.fromMap(deviceVal) : null;

  final protVal = map['protocols'];
  final protocols = protVal is List
      ? protVal.map((e) => e.toString()).toList()
      : null;

  return PrinterEvent(
    type: type,
    message: map['message'] as String?,
    device: device,
    protocols: protocols,
  );
}