doc_scanner 0.0.1 copy "doc_scanner: ^0.0.1" to clipboard
doc_scanner: ^0.0.1 copied to clipboard

discontinued
PlatformAndroidiOS
outdated

A new Flutter FFI plugin to analyse pakistani documents like IdCard, driving license, passport.

example/lib/main.dart

import 'dart:io';

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

import 'package:doc_scanner/doc_scanner.dart' as doc_scanner;
import 'package:image_picker/image_picker.dart';

void main() {
  runApp(
    const MaterialApp(
      title: 'Doc Scanner',
      home: MyApp(),
    ),
  );
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late int sumResult;
  late Future<int> sumAsyncResult;
  final ImagePicker picker = ImagePicker();
  XFile? image;
  MemoryImage? face;
  List<String> text = [];
  Map<String, String?> idCardMap = {};

  @override
  void initState() {
    super.initState();
    sumResult = doc_scanner.sum(1, 2);
    sumAsyncResult = doc_scanner.sumAsync(3, 4);
  }

  @override
  Widget build(BuildContext context) {
    const textStyle = TextStyle(fontSize: 25);
    const spacerSmall = SizedBox(height: 10);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Packages'),
        ),
        body: SingleChildScrollView(
          child: Container(
            padding: const EdgeInsets.all(10),
            child: Center(
              child: Column(
                children: [
                  spacerSmall,
                  if (face != null) Image(image: face!),
                  if (image != null) Image.file(File(image!.path)),
                  ElevatedButton(
                    onPressed: () async {
                      image =
                          await picker.pickImage(source: ImageSource.gallery);
                      setState(() {});

                      if (image != null) {
                        text = await doc_scanner.imageToText(image!.path);
                      }
                      setState(() {});
                    },
                    child: const Text('Image to Text'),
                  ),
                  ElevatedButton(
                    onPressed: () async {
                      if (image != null) {
                        face = await doc_scanner.cropFace(image!);
                      }
                      setState(() {});
                    },
                    child: const Text('Crop Face'),
                  ),
                  ElevatedButton(
                    onPressed: () {
                      if (text.isNotEmpty) {
                        String? docType = doc_scanner
                            .documentType(doc_scanner.listToString(text));
                        if (docType!.toLowerCase().startsWith('id')) {
                          idCardMap = doc_scanner.textToIdCardMap(text);
                          if (idCardMap.isNotEmpty) {
                            // Navigator.push(
                            //   context,
                            //   MaterialPageRoute(
                            //     builder: (BuildContext context) => IdCardProfile(
                            //       image: face,
                            //       cardImage: Image.file(File(image!.path)),
                            //       backSide: Image.file(File(image!.path)),
                            //       idCardData: idCardmap,
                            //       cardType: docType,
                            //     ),
                            //   ),
                            // );
                          }
                          setState(() {});
                        }
                      }
                    },
                    child: const Text('Text To idCard Map'),
                  ),
                  spacerSmall,
                  if (text.isNotEmpty) Text(text.toString()),
                  if (idCardMap.isNotEmpty)
                    ListView.builder(
                      shrinkWrap: true,
                      physics: const NeverScrollableScrollPhysics(),
                      itemCount: idCardMap.length,
                      itemBuilder: (context, index) => ListTile(
                        title: Text(idCardMap.keys.elementAt(index)),
                        subtitle:
                            Text(idCardMap.values.elementAt(index) ?? 'null'),
                      ),
                    ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
3
likes
110
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

A new Flutter FFI plugin to analyse pakistani documents like IdCard, driving license, passport.

Documentation

API reference

License

MIT (license)

Dependencies

camera, ffi, ffigen, flutter, google_ml_kit, google_mlkit_commons, google_mlkit_face_detection, google_mlkit_selfie_segmentation, image, image_picker, intl, plugin_platform_interface, quiver, string_similarity

More

Packages that depend on doc_scanner

Packages that implement doc_scanner