receipt_recognition 0.0.3
receipt_recognition: ^0.0.3 copied to clipboard
A receipt recognizer based on Google's ML Kit.
๐ท receipt_recognition #
A Flutter package for scanning and extracting structured data from supermarket receipts using Google's ML Kit. Ideal for building expense tracking apps, loyalty programs, or any system needing receipt parsing.
โจ Features #
- ๐งพ Detect and extract text from printed receipts
- ๐ Optimized for typical supermarket layouts
- ๐ Identifies line items, totals, and store names
- โก Fast and efficient ML Kit text recognition
- ๐ฑ Works on Android and iOS
- ๐ง Easy API with callback support
๐ Getting Started #
Installation #
Add to your pubspec.yaml:
dependencies:
receipt_recognition: ^<latest_version>
Then run:
flutter pub get
Platform Setup #
Android
Update AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
iOS
Update Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is needed to scan receipts.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo library access is needed to select receipt images.</string>
๐ฆ Basic Usage #
import 'package:receipt_recognition/receipt_recognition.dart';
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
final receiptRecognizer = ReceiptRecognizer(
scanTimeout: Duration(seconds: 10),
onScanTimeout: () {
print('Scan timed out.');
},
onScanComplete: (receipt) {
print('Scan complete! Store: ${receipt.company?.formattedValue}');
print('Total: ${receipt.sum?.formattedValue}');
},
onScanUpdate: (partial) {
print('In-progress scan: ${partial.positions.length} items detected so far.');
},
);
// Load an image (from file, camera, etc.)
final inputImage = InputImage.fromFilePath('path/to/receipt.jpg');
// Process the image
final receipt = await receiptRecognizer.processImage(inputImage);
if (receipt != null) {
print('Store: ${receipt.company?.formattedValue}');
for (final item in receipt.positions) {
print('Product: ${item.product.formattedValue}, Price: ${item.price.formattedValue}');
}
print('Total: ${receipt.sum?.formattedValue}');
}
๐ฅ Advanced Example: Video Feed Integration #
For an advanced use case, we provide an example of using this package with a video feed. You can integrate it with a camera feed (via a package like camera), and continuously scan receipts in real time.
Refer to the example app for an implementation that uses live camera data to recognize and process receipts as they appear in the frame.
๐งน Clean Up #
await receiptRecognizer.close();
๐ง Model Overview #
| Class | Description |
|---|---|
RecognizedReceipt |
Represents a full parsed receipt with items, sum, and store name. |
RecognizedPosition |
A single line item on the receipt: product + price. |
RecognizedEntity<T> |
Generic wrapper for parsed values from raw text. |
RecognizedCompany |
Specialized entity for the store name. |
RecognizedAmount / RecognizedSum |
Numerical values like prices and total. |
formattedValue |
Nicely formatted display value. |
๐งพ Model Structure #
RecognizedReceipt
โโโ company: RecognizedCompany
โ โโโ value: String (e.g., "Walmart")
โโโ sum: RecognizedSum
โ โโโ value: num (e.g., 23.45)
โโโ positions: List<RecognizedPosition>
โโโ RecognizedPosition
โ โโโ product: RecognizedEntity<String>
โ โ โโโ value: "Milk"
โ โโโ price: RecognizedAmount
โ โโโ value: 2.49
โโโ ...
๐ฎ Roadmap #
- โ Long receipt support and merging mechanism
- โ Product name normalization and categorization
- โ Tax and discount detection
- โ Smart OCR region selection
- โ Multi-language receipt support
๐ค Contributing #
Contributions, suggestions, and bug reports are welcome! Feel free to open an issue or PR.
๐ License #
This package is released under the MIT License.