diff --git a/lib/flutter_scalable_ocr.dart b/lib/flutter_scalable_ocr.dart index 1196c13..1b3fbd9 100644 --- a/lib/flutter_scalable_ocr.dart +++ b/lib/flutter_scalable_ocr.dart @@ -23,7 +23,8 @@ class ScalableOCR extends StatefulWidget { this.paintboxCustom, this.cameraSelection = 0, this.torchOn, - this.lockCamera = true}) + this.lockCamera = true, + this.showTextOverlay = true}) : super(key: key); /// Offset on recalculated image left @@ -59,6 +60,9 @@ class ScalableOCR extends StatefulWidget { /// Lock camera orientation final bool lockCamera; + /// Show text overlay + final bool showTextOverlay; + @override ScalableOCRState createState() => ScalableOCRState(); } @@ -384,7 +388,8 @@ class ScalableOCRState extends State { boxTopOff: widget.boxTopOff, boxRightOff: widget.boxRightOff, boxLeftOff: widget.boxRightOff, - paintboxCustom: widget.paintboxCustom); + paintboxCustom: widget.paintboxCustom, + showTextOverlay: widget.showTextOverlay); customPaint = CustomPaint(painter: painter); } else { diff --git a/lib/text_recognizer_painter.dart b/lib/text_recognizer_painter.dart index 6a6f845..cf6bfc6 100644 --- a/lib/text_recognizer_painter.dart +++ b/lib/text_recognizer_painter.dart @@ -14,7 +14,8 @@ class TextRecognizerPainter extends CustomPainter { this.boxRightOff = 4, this.boxTopOff = 2, this.getRawData, - this.paintboxCustom}); + this.paintboxCustom, + this.showTextOverlay = true}); /// ML kit recognizer final RecognizedText recognizedText; @@ -52,6 +53,9 @@ class TextRecognizerPainter extends CustomPainter { /// Narower box paint final Paint? paintboxCustom; + /// Show text overlay + final bool showTextOverlay; + @override void paint(Canvas canvas, Size size) { scannedText = ""; @@ -121,24 +125,26 @@ class TextRecognizerPainter extends CustomPainter { var parsedText = textBlock.text; scannedText += " ${textBlock.text}"; - final ParagraphBuilder builder = ParagraphBuilder( - ParagraphStyle( - textAlign: TextAlign.left, - fontSize: 14, - textDirection: TextDirection.ltr), - ); - builder.pushStyle( - ui.TextStyle(color: Colors.white, background: background)); - builder.addText(parsedText); - builder.pop(); - - canvas.drawParagraph( - builder.build() - ..layout(ParagraphConstraints( - width: right - left, - )), - Offset(left, top), - ); + if (showTextOverlay) { + final ParagraphBuilder builder = ParagraphBuilder( + ParagraphStyle( + textAlign: TextAlign.left, + fontSize: 14, + textDirection: TextDirection.ltr), + ); + builder.pushStyle( + ui.TextStyle(color: Colors.white, background: background)); + builder.addText(parsedText); + builder.pop(); + + canvas.drawParagraph( + builder.build() + ..layout(ParagraphConstraints( + width: right - left, + )), + Offset(left, top), + ); + } } } }