我想在我的flutter应用程序中使用纸张扫描仪,这样我就可以用现代平板扫描仪一次扫描大量文档,如果有任何可靠的Package&帮助我调用扫描仪(而不是CAM(的插件,请告诉我,我会感谢你的帮助。。。
我认为这个flatter_genius_scan 3.0.24包对您很有帮助。
因此,首先在您的项目pubspec.yaml文件中添加flatter_genius_scan 3.0.24包:
(还包括open_file:^3.0.1包在您的项目pubspec.yaml文件中。(
就像:
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));
}, 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)));
}
}
然后在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,即应用程序中的minSdkVersion 19->build.gradle文件,以支持以下包:
defaultConfig {
.........
.........
minSdkVersion 19
targetSdkVersion 28
........
........
}