Printer.fromJson constructor

Printer.fromJson(
  1. Map<String, dynamic> json
)

Create Printer from JSON with validation

Implementation

factory Printer.fromJson(Map<String, dynamic> json) {
  try {
    return Printer(
      address: json['address'] as String?,
      name: json['name'] as String?,
      // Native queue records carry no type; classify them by device URI.
      connectionType:
          _getConnectionTypeFromString(json['connectionType'] as String?) ??
          (json['queueName'] != null
              ? connectionTypeFromDeviceUri(json['deviceUri'] as String?)
              : null),
      isConnected: json['isConnected'] as bool?,
      vendorId: json['vendorId']?.toString(),
      productId: json['productId']?.toString(),
      deviceUri: json['deviceUri'] as String?,
      queueName: json['queueName'] as String?,
    );
  } catch (e) {
    throw FormatException('Invalid Printer JSON format: $e');
  }
}