TruthIn Scanner
A Flutter package for barcode scanning with TruthIn product database integration. Scan barcodes and get instant access to detailed product information including nutritional facts, ingredients, ratings, and health insights.
Platform Support
This package currently supports Android and iOS platforms only.
| Platform | Support |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| Web | ❌ |
| Desktop | ❌ |
Features
- Fast Barcode Scanning: Real-time barcode detection with camera preview
- Multiple Format Support: Supports EAN13, UPC-A, EAN8, UPC-E, ITF, Code39, and Code128
- Product Information: Detailed product data including:
- Product name, brand, and images
- TruthIn health ratings
- Nutritional facts and serving sizes
- Ingredient lists and additives
- Allergen information
- Health tags and dietary information
- Integrated API: Built-in API client for TruthIn product database
- Customizable: Support for custom base URLs and configuration
- Easy Integration: Simple API key initialization
Upcoming Features
We're actively working on enhancing the package with the following features:
- UI Customization: Full customization support for fonts, colors, and other UI-related configurations
- Dark Mode Support: Native dark mode theme support for better user experience
- Reduced Package Footprint: Optimizations to decrease the overall package size and improve performance
- Performance Optimizations: Enhanced scanning speed and reduced memory consumption
- Dependency Override Protocols: Ability to use app-level dependencies for API calls, giving you more control over HTTP clients and networking libraries
Stay tuned for these updates in future releases!
Installation
Add truthinscanner to your pubspec.yaml:
dependencies:
truthinscanner: ^0.0.2-dev6
Then run:
flutter pub get
Requirements
Platforms: Android and iOS only (Web and Desktop are not supported)
- Flutter SDK: >=3.22.0
- Dart SDK: >=3.4.0
- iOS: 11.0 or higher
- Android: API level 21 (Android 5.0) or higher
Platform-Specific Setup
iOS
Add camera permissions to your ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan barcodes</string>
Android
Add camera permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
Usage
1. Initialize the Package
Initialize TruthInScanner with your API key in main.dart before running your app:
import 'package:flutter/material.dart';
import 'package:truthinscanner/truthinscanner.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize TruthInScanner with your API key
TruthInScanner.initialize(
apiKey: 'your-api-key-here',
// baseUrl: 'https://custom-api-url.com/', // Optional: custom base URL
);
runApp(MyApp());
}
2. Use the Barcode Scanner
Add the BarcodeScannerView widget to your app:
import 'package:flutter/material.dart';
import 'package:truthinscanner/truthinscanner.dart';
class ScannerPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Scan Product'),
),
body: BarcodeScannerView(),
);
}
}
3. Navigate to Scanner
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BarcodeScannerView(),
),
);
},
child: Text('Scan Barcode'),
)
Complete Example
import 'package:flutter/material.dart';
import 'package:truthinscanner/truthinscanner.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize TruthInScanner
TruthInScanner.initialize(
apiKey: 'your-api-key-here',
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'TruthIn Scanner Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TruthIn Scanner'),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.qr_code_scanner,
size: 100,
color: Colors.blue,
),
SizedBox(height: 40),
Text(
'Scan Product Barcodes',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 60),
ElevatedButton.icon(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BarcodeScannerView(),
),
);
},
icon: Icon(Icons.qr_code_scanner),
label: Text('Start Scanning'),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(
horizontal: 32,
vertical: 16,
),
),
),
],
),
),
);
}
}
API Reference
TruthInScanner
Main initialization class for the package.
Methods
initialize({required String apiKey, String? baseUrl})
Initialize the scanner with your API key. Must be called before using any scanner functionality.
Parameters:
apiKey(String, required): Your TruthIn API keybaseUrl(String, optional): Custom base URL for API calls
TruthInScanner.initialize(
apiKey: 'your-api-key',
baseUrl: 'https://custom-url.com/', // Optional
);
apiKey (getter)
Get the configured API key. Throws an exception if not initialized.
isInitialized (getter)
Check if TruthInScanner has been initialized.
if (TruthInScanner.instance.isInitialized) {
// Scanner is ready
}
BarcodeScannerView
The main barcode scanner widget with camera preview.
class BarcodeScannerView extends StatefulWidget
Features:
- Real-time barcode detection
- Camera preview with detection visualization
- Automatic product lookup
- Bottom sheet with product details
- Support for multiple barcode formats
ProductsApi (Advanced)
Direct access to the TruthIn API for advanced use cases.
import 'package:truthinscanner/truthinscanner.dart';
// Get product details
final api = ProductsApi();
final productDetails = await api.getProductDetail(
barcode: '1234567890123',
);
Supported Barcode Formats
- EAN13 - European Article Number (13 digits)
- UPC-A - Universal Product Code (12 digits)
- EAN8 - European Article Number (8 digits)
- UPC-E - Compressed UPC code
- ITF - Interleaved 2 of 5
- Code39 - Standard barcode format
- Code128 - High-density barcode format
Configuration
Custom API Base URL
To use a custom API endpoint:
TruthInScanner.initialize(
apiKey: 'your-api-key',
baseUrl: 'https://your-custom-api.com/',
);
Environment Variables
You can also configure the base URL using environment variables:
flutter run --dart-define=API_URL=https://your-custom-api.com/
Error Handling
The package handles various error scenarios:
- Product Not Found: Displays a not found screen with options to upload product images
- Product Under Review: Shows a review pending message
- Network Errors: Handled gracefully with user feedback
- Camera Permissions: Prompts user to grant camera access
Troubleshooting
Camera Not Working
iOS: Ensure camera permissions are added to Info.plist
Android: Verify camera permissions in AndroidManifest.xml and request runtime permissions
API Key Issues
If you see "TruthInScanner not initialized" error:
- Ensure
TruthInScanner.initialize()is called inmain()beforerunApp() - Verify your API key is correct
Build Errors
Run these commands to resolve dependency issues:
flutter clean
flutter pub get
Dependencies
This package uses:
camera- Camera functionalitygoogle_mlkit_barcode_scanning- ML Kit barcode scanningdio- HTTP client for API callsflutter_svg- SVG renderingshimmer- Loading animationsauto_size_text- Responsive textvisibility_detector- Widget visibility detectionpermission_handler- Runtime permissions handling
Example App
Check the example/ directory for a complete working example:
cd example
flutter run
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues, questions, or feature requests, please file an issue on the GitHub repository.
API Key
To get your TruthIn API key, contact TruthIn support or visit the TruthIn developer portal.
Made with ❤️ by the TruthIn team
Libraries
- api/api_services
- api/base_api
- api/models/api_error
- api/models/api_response
- api/models/general_response
- api/models/product_status
- api/models/product_tag
- api/models/tag_details
- api/products_api
- common/widgets/blur_view
- product_detail/components/customscale
- product_detail/components/expansion_widget
- product_detail/components/get_5_nutrients
- product_detail/components/ingredents_bottom_sheet
- product_detail/components/myda_bottomsheet
- product_detail/components/nutrient_row
- product_detail/components/nutristion_facts
- product_detail/components/popups/addtivies_popup
- product_detail/components/popups/nutrifacts_popup
- product_detail/components/popups/rating_explanation
- product_detail/components/popups/rating_popup
- product_detail/components/popups/tag_details_popup
- product_detail/components/product_detail_shimmer
- product_detail/components/product_overview_card
- product_detail/components/truthin_rating_widget
- product_detail/not_found
- product_detail/product_details_page
- product_detail/test
- product_detail/utils
- scanner/components/barcode_detector_painter
- scanner/components/camera_view
- scanner/components/coordinates_translator
- scanner/models/product_detail
- scanner/scanner
- theme/theme
- truthin_scanner
- truthinscanner
- TruthIn Scanner Package
- utils/extensions
- utils/utils