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

discontinued
PlatformAndroidiOS

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

example/lib/main.dart

import 'package:flutter/material.dart';

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

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
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Doc Scanner'),
      ),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  ElevatedButton(
                      onPressed: () async {
                        image =
                            await picker.pickImage(source: ImageSource.camera);
                        setState(() {});
                      },
                      child: const Text('Pick Image Camera')),
                  ElevatedButton(
                      onPressed: () async {
                        image =
                            await picker.pickImage(source: ImageSource.gallery);
                        setState(() {});
                      },
                      child: const Text('Pick Image Gallery')),
                ],
              ),
              if (image != null) Image.file(File(image!.path)),
              ElevatedButton(
                onPressed: () async {
                  if (image != null) {
                    face = await doc_scanner.cropFace(image!);
                    setState(() {});
                  } else {
                    ScaffoldMessenger.of(context).showSnackBar(
                        const SnackBar(content: Text('Pick Image First')));
                  }
                },
                child: const Text('Crop Face'),
              ),
              if (face != null) Image(image: face!),
              ElevatedButton(
                onPressed: () async {
                  if (image != null) {
                    text = await doc_scanner.imageToText(image!.path);
                  } else {
                    ScaffoldMessenger.of(context).showSnackBar(
                        const SnackBar(content: Text('Pick Image First')));
                  }
                  setState(() {});
                },
                child: const Text('Extract Text'),
              ),
              if (text.isNotEmpty) Text(text.toString()),
              ElevatedButton(
                onPressed: () {
                  if (text.isNotEmpty) {
                    String? docType = doc_scanner
                        .documentType(doc_scanner.listToString(text));
                    if (docType!.toLowerCase().startsWith('id')) {
                      idCardMap = doc_scanner.textToIdCardMap(text);
                      // idCardMap = doc_scanner.textToDrivingLicenceMap(doc_scanner.listToString(text));
                      // idCardMap = doc_scanner.textToPassportMap(doc_scanner.listToString(text));
                      if (idCardMap.isNotEmpty) {}
                      setState(() {});
                    }
                  } else {
                    ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
                        content:
                            Text('Pick Image and then Extract Text first')));
                  }
                },
                child: const Text('Text To idCard Map'),
              ),
              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
105
points
16
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