'Is it possible to scan documents in a flutter?
Is there a way to scan documents in a flutter, I have checked some of the QR code scanners are there QR-code scanner library. How can I scan the documents and save by using the flutter or do I need to write native code to utilize this.
Solution 1:[1]
inside pubspec.yaml
barcode_scan: ^1.0.0
inside main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/services.dart';
void main() => runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: QRApp(),
));
class QRApp extends StatefulWidget {
@override
QRAppState createState() {
return new QRAppState();
}
}
class QRAppState extends State<QRApp> {
String result = "Scan QR Code Or BAR Code And Get Result Here !";
Future _scanQR() async {
try {
String qrResult = await BarcodeScanner.scan();
setState(() {
result = qrResult;
});
} on PlatformException catch (ex) {
if (ex.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
result = "Camera permission was denied";
});
} else {
setState(() {
result = "Unknown Error $ex";
});
}
} on FormatException {
setState(() {
result = "You pressed the back button before scanning anything";
});
} catch (ex) {
setState(() {
result = "Unknown Error $ex";
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("QR Scanner"),
),
body: Center(
child: Container(
// padding: EdgeInsets.all(50),
alignment: Alignment.center,
margin: const EdgeInsets.only(top: 30.0,left:30.0,right: 30.0),
child:
SelectableText(result+"\n\n\n"+"Select Above Result And copy",
cursorColor: Colors.red,
showCursor: true,
style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),
toolbarOptions: ToolbarOptions(
copy: true,
selectAll: true,
cut: false,
paste: false
),
),
),
),
floatingActionButton: FloatingActionButton.extended(
icon: Icon(Icons.camera_alt),
label: Text("Scan"),
onPressed: _scanQR,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BAPPA SAIKH |
