normalizeFile method

  1. @override
Future<NormalizedImage?> normalizeFile(
  1. String file,
  2. dynamic points
)
override

Normalize documents. file - path to the file. points - points of the document.

Implementation

@override
Future<NormalizedImage?> normalizeFile(String file, dynamic points) async {
  Offset offset = points[0];
  int x1 = offset.dx.toInt();
  int y1 = offset.dy.toInt();

  offset = points[1];
  int x2 = offset.dx.toInt();
  int y2 = offset.dy.toInt();

  offset = points[2];
  int x3 = offset.dx.toInt();
  int y3 = offset.dy.toInt();

  offset = points[3];
  int x4 = offset.dx.toInt();
  int y4 = offset.dy.toInt();
  Map? result = await methodChannel.invokeMapMethod<String, dynamic>(
    'normalizeFile',
    {
      'file': file,
      'x1': x1,
      'y1': y1,
      'x2': x2,
      'y2': y2,
      'x3': x3,
      'y3': y3,
      'x4': x4,
      'y4': y4
    },
  );

  if (result != null) {
    var data = result['data'];

    if (data is List) {
      return NormalizedImage(
        Uint8List.fromList(data.cast<int>()),
        result['width'],
        result['height'],
      );
    }

    return NormalizedImage(
      data,
      result['width'],
      result['height'],
    );
  }

  return null;
}