initialize method

Future<List<Line>?> initialize(
  1. Map<String, dynamic> output, {
  2. List<String> removeFromTopWords = const [],
  3. List<String> removeFromTopWords2 = const [],
})

***** ***** ***** ***** ***** INITIAL_AND_USEFUL_FUNCTIONS ***** ***** ***** *****


extracts each every word has a feature that takes a list of String (removeFromTopWords) and finds out which one of them is the highest and removes the upper words! removeFromTopWords2 removes the words themselves too. example of a valid list: " name ", " seat ", " type ". don't forget the space!

Implementation

///extracts each every word
///has a feature that takes a list of String (removeFromTopWords) and finds out which one of them is the
/// highest and removes the upper words! removeFromTopWords2 removes the words themselves too.
///example of a valid list: [" name ", " seat ", " type "]. don't forget the space!
Future<List<Line>?> initialize(Map<String, dynamic> output,
    {List<String> removeFromTopWords = const [],
    List<String> removeFromTopWords2 = const []}) async {
  dynamic sentValue = output["values"];
  int orientation = int.parse(output["orientation"].toString());
  // String path = output["path"];
  googleText = output["text"];
  // mhc.resetPicListDeletePics(path);
  if (sentValue == null) {
    return [];
  } else {
    var data = {"items": jsonDecode(sentValue)};
    Object obj = Object.fromJson(data);
    List<Line>? lines = [];
    if (orientation == 0) {
      Line maxXLine = obj.lines!.reduce((value, element) =>
          value.cornerList![2].x > element.cornerList![2].x
              ? value
              : element);
      var maxX = maxXLine.cornerList![2].x;
      for (var element in obj.lines!) {
        Line line = Line(
          text: element.text,
          cornerList: [
            CornerPoint(
                x: element.cornerList![0].y,
                y: maxX - element.cornerList![0].x),
            CornerPoint(
                x: element.cornerList![1].y,
                y: maxX - element.cornerList![1].x),
            CornerPoint(
                x: element.cornerList![2].y,
                y: maxX - element.cornerList![2].x),
            CornerPoint(
                x: element.cornerList![3].y,
                y: maxX - element.cornerList![3].x)
          ],
        );
        lines.add(line);
      }
    } else if (orientation == 5) {
      for (var element in obj.lines!) {
        Line line = Line(
          text: element.text,
          cornerList: [
            CornerPoint(
                x: element.cornerList![3].x, y: element.cornerList![3].y),
            CornerPoint(
                x: element.cornerList![0].x, y: element.cornerList![0].y),
            CornerPoint(
                x: element.cornerList![1].x, y: element.cornerList![1].y),
            CornerPoint(
                x: element.cornerList![2].x, y: element.cornerList![2].y),
          ],
        );
        lines.add(line);
      }
    } else {
      ///orientation here is 3
      lines = obj.lines;
    }
    // if (removeFromTopWords.isNotEmpty || removeFromTopWords2.isNotEmpty) {
    //   double minX = 0;
    //   double maxX = 0;
    //   for (Line l in lines!) {
    //     for (String s in removeFromTopWords) {
    //       if (" ${l.text!} ".toLowerCase().contains(s.toLowerCase())) {
    //         if (l.cornerList![0].x < minX || minX == 0) {
    //           minX = l.cornerList![0].x + 0.1;
    //         }
    //       }
    //     }
    //     for (String s in removeFromTopWords2) {
    //       if (" ${l.text!} ".toLowerCase().contains(s.toLowerCase())) {
    //         if (l.cornerList![2].x > maxX) maxX = l.cornerList![2].x + 0.1;
    //       }
    //     }
    //   }
    //   if (maxX > minX) minX = maxX;
    //   if (minX != 0) {
    //     for (int i = lines.length - 1; i >= 0; i--) {
    //       Line l = lines[i];
    //       if (l.cornerList![2].x <= minX) {
    //         lines.removeWhere((e) => e == l);
    //       }
    //     }
    //   }
    // }
    int i = 0;
    for (var e in lines!) {
      if (i < (e.text?.length ?? 0)) {
        i = e.text!.length;
      }
    }
    averageLineLength = (i < 12) ? (i ~/ 2) : ((i * 5) ~/ 12);
    return lines;
  }
}