flutter_zxing icon indicating copy to clipboard operation
flutter_zxing copied to clipboard

App crash when width/height are too bigger in encodeBarcode()

Open romgrm opened this issue 1 year ago • 0 comments

Hello :)

I want to generate a barcode in aztec format. So I use the encodeBarcode() method, to which I send the data and set the parameters. The default width/height (120px) doesn't work for me, so I increase it.

class BarcodeGeneratorService implements BarcodeGeneratorInterface {
  final Zxing _barcodeGenerator;

  BarcodeGeneratorService({Zxing? flutterZxing}) : _barcodeGenerator = flutterZxing ?? Zxing();
  @override
  Uint8List? encode({
    required String textToEncode,
    required int format,
    required int width,
    required int height,
    required int margin,
  }) {
    final encoded = _barcodeGenerator.encodeBarcode(
        contents: textToEncode,
        params: EncodeParams(format: Format.aztec,  width: 150, height: 150 , eccLevel: EccLevel.high));

    if (!encoded.isValid || encoded.data == null) {
      return null;
    }
    final imglib.Image img = imglib.Image.fromBytes(
      150,
      150,
      encoded.data!,
    );
    return Uint8List.fromList(
      imglib.encodeJpg(img),
    );
  }
}

When I want to display my barcode, when the encodeBarcode() method is triggered, my application crashes at this point.

The crash occurs on several physical iOS devices, in 16 and 16.5. On the other hand, everything works fine on simulator.

The error is not very clear:

image

Do you have any idea what it could be?

Thanks :)

romgrm avatar Jul 18 '23 19:07 romgrm