๐Ÿ“ท receipt_recognition

Pub Version Pub Points Likes License Last Commit

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(
  videoFeed: false,
  scanTimeout: Duration(seconds: 10),
  onScanTimeout: () {
    print('Scan timed out.');
  },
  onScanComplete: (receipt) {
    print('Scan complete! Store: ${receipt.company?.formattedValue}');
    print('Total: ${receipt.sum?.formattedValue}');
  },
  onScanUpdate: (scanProgress) {
    if (scanProgress.estimatedPercentage != null) {
      print('In-progress scan: ${scanProgress.estimatedPercentage}% 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.
RecognizedProduct Alphanumeric value for product.
RecognizedPrice Numerical value for price.
RecognizedSum Numerical value for sum.
RecognizedSumLabel Represents the detected label for the sum.
RecognizedCompany Specialized entity for the store name.

๐Ÿงพ Model Structure

RecognizedReceipt
โ”œโ”€โ”€ company: RecognizedCompany
โ”‚   โ””โ”€โ”€ value: String (e.g., "Walmart")
โ”œโ”€โ”€ sum: RecognizedSum
โ”‚   โ””โ”€โ”€ value: num (e.g., 23.45)
โ””โ”€โ”€ positions: List<RecognizedPosition>
     โ”œโ”€โ”€ RecognizedPosition
     โ”‚   โ”œโ”€โ”€ product: RecognizedProduct
     โ”‚   โ”‚   โ””โ”€โ”€ value: "Milk"
     โ”‚   โ””โ”€โ”€ price: RecognizedPrice
     โ”‚       โ””โ”€โ”€ value: 2.49
     โ””โ”€โ”€ ...

๐Ÿ“ฆ Release Notes

See the CHANGELOG.md for a complete list of updates and version history.


๐Ÿ”ฎ Roadmap

  • x Product name normalization
  • x Long receipt support and merging mechanism
  • TSE detection 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.