printPriceTag static method

Future<String?> printPriceTag(
  1. PriceTagData priceTag, {
  2. int copies = 1,
  3. bool downToUp = true,
})

Implementation

static Future<String?> printPriceTag(
  PriceTagData priceTag, { int copies = 1, bool downToUp = true }) async {

  if (copies <= 0) {
    _status = 'Copies should be between 1 and 20';
    print(_status);
    return _status;
  }

  final content = await PriceTagLayout.buildDocument(priceTag);
  SewooDocument document = SewooDocument(
    content: content,
    downToUp: downToUp
  );

  final String path = await _saveDocument( document );

  if ( await _checkStoragePermission() ) {
    String status = 'Printing';

    try {
      bool success = await (_channel.invokeMethod('printImage', <String, dynamic> {
        "path": path,
        "width": _mm2dots( 39 ),
        "height": _mm2dots( 102 ),
        "copies": copies
      }) as FutureOr<bool>);
      status = success ? 'Success' : 'Fail: Image not found';

    } on PlatformException catch (e) {
      status = 'Failed: ${e.message}';
    }
    _status = status;

  } else {
    _status = 'Permission Denied';
  }
  return _status;
}