@@ -18,7 +18,7 @@ class _TextFromWidgetViewState extends State<TextFromWidgetView> {
18
18
final _widgetKey = GlobalKey ();
19
19
String _extractedText = 'Recognized text will appear here' ;
20
20
bool _isBusy = false ;
21
-
21
+
22
22
@override
23
23
void dispose () {
24
24
_textRecognizer.close ();
@@ -90,16 +90,16 @@ class _TextFromWidgetViewState extends State<TextFromWidgetView> {
90
90
91
91
Future <void > _extractTextFromWidget () async {
92
92
if (_isBusy) return ;
93
-
93
+
94
94
setState (() {
95
95
_isBusy = true ;
96
96
_extractedText = 'Processing...' ;
97
97
});
98
98
99
99
try {
100
100
// Get the RenderObject from the GlobalKey
101
- final RenderRepaintBoundary ? boundary =
102
- _widgetKey.currentContext ? .findRenderObject () as RenderRepaintBoundary ? ;
101
+ final RenderRepaintBoundary ? boundary = _widgetKey.currentContext
102
+ ? .findRenderObject () as RenderRepaintBoundary ? ;
103
103
104
104
if (boundary == null ) {
105
105
setState (() {
@@ -111,11 +111,11 @@ class _TextFromWidgetViewState extends State<TextFromWidgetView> {
111
111
112
112
// Capture the widget as an image
113
113
final ui.Image image = await boundary.toImage (pixelRatio: 3.0 );
114
-
114
+
115
115
// Convert to byte data in raw RGBA format
116
- final ByteData ? byteData =
116
+ final ByteData ? byteData =
117
117
await image.toByteData (format: ui.ImageByteFormat .rawRgba);
118
-
118
+
119
119
if (byteData == null ) {
120
120
setState (() {
121
121
_extractedText = 'Error: Failed to get image byte data' ;
@@ -125,21 +125,21 @@ class _TextFromWidgetViewState extends State<TextFromWidgetView> {
125
125
}
126
126
127
127
final Uint8List bytes = byteData.buffer.asUint8List ();
128
-
128
+
129
129
// Create InputImage from bitmap data with dimensions
130
130
final inputImage = InputImage .fromBitmap (
131
131
bitmap: bytes,
132
132
width: image.width,
133
133
height: image.height,
134
134
);
135
-
135
+
136
136
// Process the image with the text recognizer
137
- final RecognizedText recognizedText =
137
+ final RecognizedText recognizedText =
138
138
await _textRecognizer.processImage (inputImage);
139
-
139
+
140
140
setState (() {
141
- _extractedText = recognizedText.text.isNotEmpty
142
- ? recognizedText.text
141
+ _extractedText = recognizedText.text.isNotEmpty
142
+ ? recognizedText.text
143
143
: 'No text recognized' ;
144
144
_isBusy = false ;
145
145
});
0 commit comments