document_scanner_flutter 0.2.0 document_scanner_flutter: ^0.2.0 copied to clipboard
A android & ios document scanner & auto detetctor plugin for flutter.
import 'dart:io';
import 'package:document_scanner_flutter/document_scanner_flutter.dart';
import 'package:document_scanner_flutter/configs/configs.dart';
import 'package:flutter/material.dart';
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
PDFDocument? _scannedDocument;
File? _scannedDocumentFile;
File? _scannedImage;
openPdfScanner(BuildContext context) async {
var doc = await DocumentScannerFlutter.launchForPdf(context,
androidConfigs: {
ScannerConfigsAndroid.ANDROID_NEXT_BUTTON_TITLE: "Next Step"
});
if (doc != null) {
_scannedDocument = null;
setState(() {});
await Future.delayed(Duration(milliseconds: 100));
_scannedDocumentFile = doc;
_scannedDocument = await PDFDocument.fromFile(doc);
setState(() {});
}
}
openImageScanner(BuildContext context) async {
var image = await DocumentScannerFlutter.launch(context,
//source: ScannerFileSource.CAMERA,
androidConfigs: {
ScannerConfigsAndroid.ANDROID_NEXT_BUTTON_TITLE: "Next Step"
});
if (image != null) {
_scannedImage = image;
setState(() {});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (_scannedDocument != null || _scannedImage != null) ...[
if (_scannedImage != null)
Image.file(_scannedImage!,
width: 300, height: 300, fit: BoxFit.contain),
if (_scannedDocument != null)
Expanded(
child: PDFViewer(
document: _scannedDocument!,
)),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
_scannedDocumentFile?.path ?? _scannedImage?.path ?? ''),
),
],
Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () => openPdfScanner(context),
child: Text("PDF Scan"));
}),
),
Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () => openImageScanner(context),
child: Text("Image Scan"));
}),
)
],
),
),
);
}
}