1

I try use google_mlkit_text_recognition in flutter app but I got "Errors" with some virables in flutter?

    final inputImage = InputImage.fromFilePath(path!.path);
    final textRecognizer = TextRecognizer(script: TextRecognitionScript.latin);
    final RecognizedText recognizedText = await textRecognizer.processImage(inputImage);

String text = recognizedText.text;
for (TextBlock block in recognizedText.blocks) {
  final Rect rect = block.rect;`Error` <=`The getter  'rect' isn't defined for the type 'TextBlock'.
Try importing the library that defines 'rect', correcting the name to the name of an existing getter, or defining a getter or field named 'rect'`
  final List<Offset> cornerPoints = block.cornerPoints; `Error`<=`A value of type 'List<Point<int>>' can't be assigned to a variable of type 'List<Offset>'.
Try changing the type of the variable, or casting the right-hand type to 'List<Offset>'`
  final String text = block.text;
  final List<String> languages = block.recognizedLanguages;

  for (TextLine line in block.lines) {
    // Same getters as TextBlock
    for (TextElement element in line.elements) {
      // Same getters as TextBlock
    }
  }
}
  }```





I want to make google_mlkit_text_recognition inside method to extract text from photo 

1 Answers1

0

Its because rect is not a property of TextBlock, I assume it may be from some other package try this

import 'package:package_name/file_name.dart' as RectPackage; in that specific package.

and then to use do RectPackage.Rect or any other class just use RectPackage at the start of that line.(note: RectPackage is just an example)

or maybe you just messed up with the variable name change it as for loop var name and the one in Rect are named the same.

Bibek Saha
  • 134
  • 1
  • 7