SunmiBarcodeStyle constructor
SunmiBarcodeStyle({
- int size = 4,
- int height = 162,
- SunmiBarcodeTextPos textPos = SunmiBarcodeTextPos.NO_TEXT,
- SunmiBarcodeType type = SunmiBarcodeType.CODE128,
- SunmiPrintAlign align = SunmiPrintAlign.CENTER,
Factory constructor to create a SunmiBarcodeStyle object with default values and optional customizations.
This method validates the size and height to ensure they fall within valid ranges.
size determines the thickness of barcode bars (1 to 16, default: 4).
height determines the height of the barcode (1 to 255, default: 162).
textPos specifies text position relative to the barcode (default: NO_TEXT).
type specifies the barcode type (default: CODE128).
align specifies the alignment of the barcode (default: CENTER).
Implementation
factory SunmiBarcodeStyle({
int size = 4,
int height = 162,
SunmiBarcodeTextPos textPos = SunmiBarcodeTextPos.NO_TEXT,
SunmiBarcodeType type = SunmiBarcodeType.CODE128,
SunmiPrintAlign align = SunmiPrintAlign.CENTER,
}) {
// Validate the size to ensure it falls within the valid range of 1 to 16.
if (size < 1 || size > 16) {
throw ArgumentError(
'Invalid size: $size. Must be between 1 and 16.',
);
}
// Validate the height to ensure it falls within the valid range of 1 to 255.
if (height < 1 || height > 255) {
throw ArgumentError(
'Invalid height: $height. Must be between 1 and 255.',
);
}
// Return a new instance of SunmiBarcodeStyle with the provided or default values.
return SunmiBarcodeStyle._internal(
align: align,
height: height,
size: size,
textPos: textPos,
type: type,
);
}