flutter_scalable_ocr 2.0.0 flutter_scalable_ocr: ^2.0.0 copied to clipboard
Flutter scalable OCR package is a wrapper around google_mlkit_text_recognition where you can partialy select part of camera which text will be processed of.
import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_scalable_ocr/flutter_scalable_ocr.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Scalable OCR',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Scalable OCR'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String text = "";
final StreamController<String> controller = StreamController<String>();
void setText(value) {
controller.add(value);
}
@override
void dispose() {
controller.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ScalableOCR(
paintboxCustom: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 4.0
..color = const Color.fromARGB(153, 102, 160, 241),
boxLeftOff: 5,
boxBottomOff: 2.5,
boxRightOff: 5,
boxTopOff: 2.5,
boxHeight: MediaQuery.of(context).size.height / 3,
getRawData: (value) {
inspect(value);
},
getScannedText: (value) {
setText(value);
}),
StreamBuilder<String>(
stream: controller.stream,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
return Result(text: snapshot.data != null ? snapshot.data! : "");
},
)
],
),
));
}
}
class Result extends StatelessWidget {
const Result({
Key? key,
required this.text,
}) : super(key: key);
final String text;
@override
Widget build(BuildContext context) {
return Text("Readed text: $text");
}
}