在Flutter App中调用平板纸扫描仪

问题描述

我想在Flutter应用程序中使用纸张扫描仪,所以我可以使用现代平板扫描仪一次扫描很多文档,如果有任何可靠的Packages和Plugin可以帮助我调用扫描仪(不是CAM),请让我知道,谢谢您的帮助...

解决方法

我认为此 flutter_genius_scan 3.0.24 软件包对您有所帮助。

因此,首先在您的项目 pubspec.yaml 文件中添加此 flutter_genius_scan 3.0.24 软件包:

(还要在您的项目pubspec.yaml文件中包含 open_file:^ 3.0.1 包。)

就像:

dependencies:
  flutter_genius_scan: ^3.0.24
  open_file: ^3.0.1

然后创建新的Dart页面并命名为 Scanning_Page ,然后在其中添加以下代码。

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));
              },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)));
  }
}

然后在您的 main.dart 文件中使用以下代码:

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(),);
  }
}

注意::您的 minSdkVersion 必须为 19 ,即 app->版本中的 minSdkVersion 19 。 gradle 文件以支持以下程序包,例如bellow:

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