quickcapture 1.0.10 quickcapture: ^1.0.10 copied to clipboard
QuickCapture AI Based Mobile Document Scanning plugin for Flutter From Extrieve.
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:open_file/open_file.dart';
import 'package:fluttertoast/fluttertoast.dart';
//Import Quickcapture flutter plugin
import 'package:quickcapture/quickcapture.dart';
void main() {
runApp(const MyApp());
}
typedef MyCallback = void Function(String result);
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<String> _capturedImage = [];
//final _quickcapturePlugin = Quickcapture();
final _quickcapturePlugin = Quickcapture();
@override
void initState() {
super.initState();
//Do license activation before initialisation (if license available - optional)
activateLicense();
//initalise plugin
_quickcapturePlugin.initialize();
}
Future<void> startCapture() async {
String? response = await _quickcapturePlugin.startCapture();
setState(() {
// Assuming your JSON response is stored in the variable 'response'
Map<String, dynamic> jsonResponse = jsonDecode(response!);
// Extract the list of image paths from the 'fileCollection' key
_capturedImage = List<String>.from(jsonResponse['fileCollection']);
});
}
Future<void> buildPDF() async {
String? response = await _quickcapturePlugin.buildPDFForLastCapture();
OpenFile.open(response);
}
Future<void> activateLicense() async {
String androidLicense = "<Pass license for android here>";
String iosLicense = "<Pass the license string for IOS here>";
bool? response = await _quickcapturePlugin.activateLicense(
android: androidLicense, ios: iosLicense);
String lisMsg = "License activation failed.Invalid license";
Color bgColor =
const Color.fromARGB(255, 216, 90, 58); // Use green for success
if (response != null && response == true) {
lisMsg = "License for android activated";
bgColor = const Color.fromARGB(255, 58, 216, 84);
}
Fluttertoast.showToast(
msg: lisMsg,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: bgColor,
textColor: Colors.white,
fontSize: 16.0);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('QuickCapture'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_capturedImage.isNotEmpty
? Expanded(
child: ImageGrid(_capturedImage),
)
: Container(),
ElevatedButton(
onPressed: () => startCapture(),
child: const Text("Start capture"),
),
ElevatedButton(
onPressed: () => buildPDF(),
child: const Text("Build PDF"),
),
],
),
),
),
);
}
}
class ImageGrid extends StatelessWidget {
final List<String> imagePaths;
const ImageGrid(this.imagePaths, {super.key});
@override
Widget build(BuildContext context) {
return GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, // Number of images per row
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
),
itemCount: imagePaths.length,
itemBuilder: (context, index) {
return Image.file(
File(imagePaths[index]),
width: 200,
height: 200,
fit: BoxFit.contain,
);
},
);
}
}