getBarcodesFromImage method

  1. @override
Future<BarcodeData?> getBarcodesFromImage([
  1. String path = ""
])
override

Implementation

@override
Future<BarcodeData?> getBarcodesFromImage([String path = ""]) async {
  bool validPath = await File.fromUri(Uri(path: path)).exists();
  if(!validPath) throw Exception("Invalid Image Path");

  // if(Platform.isAndroid) return null;
  String? barJson = await methodChannel.invokeMethod<String?>('getBarcodesFromPath', {"path": path});
  if (barJson == null) return null;
  try {
    BarcodeData barData = BarcodeData.fromJson(jsonDecode(barJson));
    if(barData.barcodes.isEmpty){
      final Image? capturedImage = decodeImage(await File(path).readAsBytes());
      final Image orientedImage = bakeOrientation(capturedImage!);
      await File(path).writeAsBytes(encodeJpg(orientedImage));
      String? barJsonRotated =
      await methodChannel.invokeMethod<String?>('getBarcodesFromPath', {"path": path});
      if (barJsonRotated == null) return null;
      BarcodeData ro = BarcodeData.fromJson(jsonDecode(barJsonRotated));
      return ro;
    }else {
      return barData;
    }
  } catch (e) {
    return null;
  }
}