Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/flutter_scalable_ocr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,6 +60,9 @@ class ScalableOCR extends StatefulWidget {
/// Lock camera orientation
final bool lockCamera;

/// Show text overlay
final bool showTextOverlay;

@override
ScalableOCRState createState() => ScalableOCRState();
}
Expand Down Expand Up @@ -384,7 +388,8 @@ class ScalableOCRState extends State<ScalableOCR> {
boxTopOff: widget.boxTopOff,
boxRightOff: widget.boxRightOff,
boxLeftOff: widget.boxRightOff,
paintboxCustom: widget.paintboxCustom);
paintboxCustom: widget.paintboxCustom,
showTextOverlay: widget.showTextOverlay);

customPaint = CustomPaint(painter: painter);
} else {
Expand Down
44 changes: 25 additions & 19 deletions lib/text_recognizer_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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),
);
}
}
}
}
Expand Down