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?,
      connectionType: json['queueName'] != null
          ? connectionTypeFromDeviceUri(json['deviceUri'] as String?)
          : _getConnectionTypeFromString(json['connectionType'] as String?),
      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');
  }
}