๐ Mofilo Barcode Verifier
Barcode validation using GS1 algorithms for format and checksum verification. Supports EAN-13, UPC-A, EAN-8, and UPC-E formats.
๐ฏ Quick Start
import 'package:mofilo_barcode_verifier/mofilo_barcode_verifier.dart';
void main() {
final verifier = BarcodeVerifier();
// Verify a single barcode
final result = verifier.verify('5449000000996'); // EAN-13 example
if (result.isValid) {
print('โ Valid ${result.barcodeType.name} barcode');
} else {
print('โ Invalid: ${result.message}');
print('Errors: ${result.errors}');
}
}
โจ Features
- ๐ Format Support: EAN-13, UPC-A, EAN-8, UPC-E
- โ Checksum Validation: Uses GS1 standard algorithms
- โก No External Dependencies: Pure Dart implementation, no network calls
- ๐ฏ Format + Checksum: Validates both in one call
- ๐ฆ Batch Verification: Process multiple barcodes at once
- ๐งช Tested: Includes unit tests with example product barcodes
๐ฌ Validation Pipeline
1. Format Validation
- Length verification (6, 8, 12, or 13 digits)
- Numeric character validation
- Barcode type detection
2. Checksum Validation
- GS1 algorithm implementation
- Designed to detect single-digit errors
- Designed to detect most transposition errors
๐ฑ Usage Examples
Basic Validation
final verifier = BarcodeVerifier();
final result = verifier.verify('012000001970');
print(result.isValid); // true
print(result.barcodeType); // BarcodeType.upcA
print(result.message); // "Valid UPC-A barcode"
Quick Boolean Check
if (verifier.isValid('5449000000996')) {
print('Barcode is valid!');
}
Batch Verification
final barcodes = [
'5449000000996', // Coca-Cola
'8000500037447', // Nutella
'invalid123', // Invalid
];
final results = verifier.verifyBatch(barcodes);
for (final result in results) {
print('${result.barcode}: ${result.isValid}');
}
Type Detection
final type = verifier.detectType('5449000000996');
print(type); // BarcodeType.ean13
๐ Supported Barcode Types
| Type | Digits | Common Usage | Example |
|---|---|---|---|
| EAN-13 | 13 | Worldwide | 5449000000996 |
| UPC-A | 12 | North America | 012000001970 |
| EAN-8 | 8 | Small Packages | 96385074 |
| UPC-E | 6 | Compressed UPC | 425261 |
โ ๏ธ Important Notes
What This Package Does
โ Validates barcode format and checksum โ Detects barcode type (EAN-13, UPC-A, etc.) โ Works offline with zero external dependencies
What This Package Does NOT Do
โ Does NOT identify product categories or types โ Does NOT query product databases โ Does NOT determine country of origin from prefix โ Does NOT verify if barcode actually exists
Why?
GS1 barcode prefixes identify the company/manufacturer, not the product type or category. This package performs syntactic validation only - it verifies that a barcode follows the correct format and has a valid checksum.
To determine if a barcode exists or get product information, you would need to:
- Query a product database (OpenFoodFacts, GS1 GEPIR, etc.)
- Maintain your own product database
- Use additional verification layers
This package focuses on Layer 1 validation - the foundation for any barcode-based system. See PRODUCTION_VALIDATION_STRATEGY.md for multi-layer validation guidance.
๐ Validation Results
class VerificationResult {
final String barcode; // Original barcode
final bool isValid; // Validation result
final BarcodeType barcodeType; // Detected type
final VerificationStatus status; // Detailed status
final String message; // Human-readable message
final List<String> errors; // Validation errors
}
๐งช Testing
Tested with example product barcodes:
- โ Coca-Cola (EAN-13)
- โ Nutella (EAN-13)
- โ Red Bull (EAN-13)
- โ Campbell's Soup (UPC-A)
- โ Spam (UPC-A)
- โ Toblerone (EAN-13)
- โ Haribo (EAN-13)
๐ Technical Standards
Implementation references:
- GS1 General Specifications
- EAN/UPC Barcodes
- ISO/IEC 15420 (EAN/UPC)
Note: This package is not certified or endorsed by GS1.
๐ค Contributing
Issues and pull requests are welcome! Please follow the existing code style and include tests for new features.
๐ License
MIT License - see LICENSE file for details.
โ๏ธ Disclaimer
This software is provided "as is" without warranty of any kind. The authors are not liable for any damages arising from its use. This package performs syntactic validation only and does not guarantee that barcodes are valid, issued by GS1, or correspond to actual products. Users should implement additional verification for production use.
๐ Related Packages
- mofilo_nutrient_verifier - Nutrition data validation
Built by the Mofilo team ๐
mofilo_barcode_verifier
mofilo_barcode_verifier
Libraries
- mofilo_barcode_verifier
- A Flutter package for validating product barcodes.