Hello @shirsh94 , the problem am having with the package is that when the document is scan or for instance an id card is scan that portion where the scan happen is not return but instead the entire picture is return instead of only the portion that edges are return.
my sample code here:
// The scanned document may contain multiple pages, so you need to handle this accordingly.
// For simplicity, we'll assume only one page is scanned.
List<String>? scannedPages = scannedDocument as List<String>?;
if (scannedPages != null && scannedPages.isNotEmpty) {
return scannedPages.first;
} else {
throw Exception("No document scanned or error occurred during scanning.");
}
Hello @shirsh94 , the problem am having with the package is that when the document is scan or for instance an id card is scan that portion where the scan happen is not return but instead the entire picture is return instead of only the portion that edges are return. my sample code here:
import 'dart:io';
import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_doc_scanner/flutter_doc_scanner.dart';
class CameraScreen extends StatefulWidget { final CameraDescription camera; final Function(String path) onImageCaptured;
const CameraScreen({ Key? key, required this.camera, required this.onImageCaptured, }) : super(key: key);
@override _CameraScreenState createState() => _CameraScreenState(); }
class _CameraScreenState extends State {
late CameraController _controller;
late Future _initializeControllerFuture;
@override void initState() { super.initState(); _controller = CameraController( widget.camera, ResolutionPreset.medium, ); _initializeControllerFuture = _controller.initialize(); }
@override void dispose() { _controller.dispose(); super.dispose(); }
Future scanDocument(String imagePath) async {
dynamic scannedDocument;
try {
scannedDocument = await FlutterDocScanner().getScanDocuments();
} on PlatformException catch (e) {
print("Error scanning document: $e");
throw Exception("Error scanning document: $e");
}
}
@override Widget build(BuildContext context) { return Scaffold( body: FutureBuilder(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Stack(
children: [
CameraPreview(_controller),
Center(
child: Container(
height: 300,
width: 300,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 3),
),
),
),
],
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.camera_alt),
onPressed: () async {
try {
await _initializeControllerFuture;
final image = await _controller.takePicture();
String scannedImagePath = await scanDocument(image.path);
widget.onImageCaptured(scannedImagePath);
Navigator.of(context).pop();
} catch (e) {
print(e);
}
},
),
);
}
}