ocr_scan 0.1.0 copy "ocr_scan: ^0.1.0" to clipboard
ocr_scan: ^0.1.0 copied to clipboard

retracted

OCR scan library for Flutter. It can scan text form zones in preview.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:ocr_scan/ocr_scan.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  bool process = true;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Ocr Scan Example')),
        extendBody: true,
        body: Builder(builder: buildPreview),
        bottomNavigationBar: BottomAppBar(
          child: ElevatedButton.icon(
            onPressed: () {
              process = !process;
              setState(() {});
            },
            icon: const Icon(Icons.document_scanner),
            label: Text(process ? 'Stop' : 'Start'),
          ),
        ),
      ),
    );
  }

  // #docregion OcrScanPreview
  Widget buildPreview(BuildContext context) {
    final ScaffoldMessengerState messenger = ScaffoldMessenger.of(context);

    return ScanPreview(
      scanProcess: process,
      scanDuration: const Duration(milliseconds: 2000 * 3),
      textRecognizerConfig: TextRecognizerConfig(
        scanZonePainter: OcrScanZonePainter(
          elements: [
            const Zone(
              Rect.fromLTWH(40, 100, 1200, 100),
              text: TextSpan(
                text: 'Zone 1: TOP',
                style: TextStyle(backgroundColor: Colors.red),
              ),
              paintingColor: Colors.red,
            ), // Zone1 TOP
            const Zone(
              Rect.fromLTWH(40, 500, 1200, 100),
              text: TextSpan(
                text: 'Zone 2: BOTTOM',
                style: TextStyle(backgroundColor: Colors.green),
              ),
              paintingColor: Colors.green,
            ),
          ],
        ),
        onTextLine: ((int, List<TextLine>) value) {
          messenger.showSnackBar(SnackBar(
            duration: const Duration(milliseconds: 2000),
            content: Text(
              value.$2.fold(
                'Rect ${value.$1 + 1} - Length ${value.$2.length}:',
                (String pre, TextLine e) => '$pre\n${e.text}',
              ),
            ),
          ));
        },
      ),
      barcodeScannerConfig: BarcodeScannerConfig(
        scanZonePainter: BarcodeScanZonePainter(
          elements: [
            const Zone(
              Rect.fromLTWH(40, 250, 1200, 200),
              text: TextSpan(
                text: 'Zone 3: CENTER',
                style: TextStyle(backgroundColor: Colors.yellow),
              ),
              paintingColor: Colors.yellow,
            ),
          ],
        ),
        onBarcode: ((int, List<Barcode>) value) {
          messenger.showSnackBar(SnackBar(
            duration: const Duration(milliseconds: 2000),
            content: Text(
              value.$2.fold(
                'Rect 3 - Length ${value.$2.length}:',
                (String pre, Barcode e) => '$pre\n${e.displayValue}',
              ),
            ),
          ));
        },
      ),
    );
  }
  // #enddocregion OcrScanPreview
}
3
likes
0
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

OCR scan library for Flutter. It can scan text form zones in preview.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

camera, flutter, google_mlkit_barcode_scanning, google_mlkit_commons, google_mlkit_text_recognition

More

Packages that depend on ocr_scan