khoren93 / flutter_zxing

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
https://pub.dev/packages/flutter_zxing
MIT License
97 stars 56 forks source link

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

Open romgrm opened 1 year ago

romgrm commented 1 year ago

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 :)