RafaelBarbosatec / qr_code_dart_scan

A QR code scanner that works on both iOS and Android using dart decoder.
MIT License
15 stars 20 forks source link

flutter: ERROR:Null check operator used on a null value #7

Closed Noor-Mahammad closed 1 year ago

Noor-Mahammad commented 1 year ago

When I'm trying to scan a QR in live it showing me like this ERROR:Null check operator used on a null value

philseeley commented 1 year ago

Hi Rafael,

A bit more info...

I only get this on iOS and not Android:

flutter: ERROR(decodePlanes):Null check operator used on a null value

I've run in debug and the error is happening in "transformToLuminanceSource" in "decoder/global_functions.dart".

On Android (Android 13 (API 33)): e.bytesPerPixel = 0 On iOS (iOS 16.6 20G75): e.bytesPerPixel = null

The null exception is thrown during the "map" to get the "total":

  final total = planes
      .map<double>((p) => p.bytesPerPixel!.toDouble())
      .reduce((value, element) => value + 1 / element)
      .toInt();

In the definition of "Plane" in "camera_image.dart" it says:

  /// The distance between adjacent pixel samples on Android, in bytes.
  ///
  /// Will be `null` on iOS.
  final int? bytesPerPixel;

So I've put in a null test and a default of "1" in "transformToLuminanceSource" and that works for me on iOS.

I'll submit a pull request for you to check.

Cheers Phil

RafaelBarbosatec commented 1 year ago

Wow. Thanks so much @philseeley ! I'm wait anxious for your PR.