invoke flatbed paper scanner in Flutter App

537 Views Asked by At

I want to use paper scanners inside my flutter application ,so I can scan lots of documents at once with modern flatbed scanners , if there is any reliable Packages & plugins that help me to invoke scanner (not CAM ), plz let me know , I will appreciate your help ...

1

There are 1 best solutions below

0
Vaibhav_Welcomes_You On

I think this flutter_genius_scan 3.0.24 package is helpful for you.

So first add this flutter_genius_scan 3.0.24 package' in yours project pubspec.yaml file:

(Also include open_file: ^3.0.1 package in yours project pubspec.yaml file.)

Just like :

dependencies:
  flutter_genius_scan: ^3.0.24
  open_file: ^3.0.1

Then Create new Dart Page and name like Scanning_Page and add following code in it.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_genius_scan/flutter_genius_scan.dart';
import 'package:open_file/open_file.dart';

class Scanning_Page extends StatefulWidget {
  @override
  _Scanning_PageState createState() => _Scanning_PageState();
}

class _Scanning_PageState extends State<Scanning_Page> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Scan Documents'),
        ),
        body: Center(
          child: RaisedButton.icon(
            onPressed: () {
              FlutterGeniusScan.scanWithConfiguration({
                'source': 'camera',
                'multiPage': true,
              }).then((result) {
                String pdfUrl = result['pdfUrl'];
                OpenFile.open(pdfUrl.replaceAll("file://", '')).then(
                        (result) => debugPrint(result.toString()),
                    onError: (error) => displayError(context, error));
              }, onError: (error) => displayError(context, error));
            },
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(10.0))),
            label: Text('START SCANNING',
              style: TextStyle(color: Colors.white),),
            icon: Icon(Icons.scanner, color: Colors.white,),
            textColor: Colors.white,
            splashColor: Colors.red,
            color: Colors.lightBlue,),
        )
    );
  }

  void displayError(BuildContext context, PlatformException error) {
    Scaffold.of(context).showSnackBar(SnackBar(content: Text(error.message)));
  }
}

Then in your main.dart file use bellow code :

import 'package:flutter/material.dart';
import 'package:flutter_app/Scanning_Page.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Scan Documents',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home:Scanning_Page(),
    );
  }
}

Note : Your minSdkVersion must be 19 i.e minSdkVersion 19 in app -> build.gradle file to support these packages like bellow :

 defaultConfig {
        .........
        .........
        minSdkVersion 19
        targetSdkVersion 28
        ........
        ........
    }