bigship/barcode.flutter

Longer bar code renders outside canvas

bruceanwyl opened this issue · 1 comments

This is not the same as #15. That was a miscalculation of the canvas size required to paint the barcode value with the specified line width.

This issue occurs when the barcode widget is contained by a widget that is smaller than the calculated canvas size. In the example below, the barcode is in an Expanded widget between two SizedBox widgets. The code snippet below shows how the border around the canvas is applied.

    return Container(
      padding: EdgeInsets.all(8),
      decoration: BoxDecoration(
        color: Colors.red,
      ),
      child: BarCodeImage(
        data: "62733538535715976",
        codeType: BarCodeType.Code39,
        lineWidth: 2.5,
        barHeight: 150.0,
      ),
    );

long barcode outside canvas

So, rather than this, it would be better if the painter was aware of the actual width of canvas it has to work with and, if the canvas is too small, scale the barcode line width accordingly.

v0l commented

Put the BarCodeImage in a FittedBox and it will scale the barcode to your width constraints, otherwise i agree, it should use constraints to find out how much space it can use, if its not enough space it should produce an overflow like Text widget