bigship / barcode.flutter

barcode generate library for Flutter
BSD 2-Clause "Simplified" License
59 stars 27 forks source link

Longer bar code renders outside canvas #17

Open bruceanwyl opened 5 years ago

bruceanwyl commented 5 years ago

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 5 years ago

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