flutter_ml_helper 0.1.0
flutter_ml_helper: ^0.1.0 copied to clipboard
Easy integration with TensorFlow Lite and ML Kit for Flutter applications. Supports all 6 platforms with WASM compatibility.
Flutter ML Helper #
Easy integration with TensorFlow Lite and ML Kit for Flutter applications. Supports all 6 platforms with WASM compatibility.
Demo #
Features #
- 🚀 TensorFlow Lite Integration - Load and run TFLite models
- 🔥 ML Kit Support - Access Google's ML Kit capabilities
- 🌐 Cross-Platform - iOS, Android, Web, Windows, macOS, Linux
- ⚡ WASM Compatible - WebAssembly support for web platform
- 🖼️ Image Processing - Built-in image preprocessing utilities
- 📸 HEIC Support - Native HEIC image decoding on iOS/Android
- 🔐 Permission Handling - Automatic permission management
- 📱 Mobile Optimized - Efficient resource management
Platform Support #
| Platform | Status | Notes |
|---|---|---|
| iOS | ✅ Supported | Full TFLite and ML Kit support |
| Android | ✅ Supported | Full TFLite and ML Kit support |
| Web | ✅ Supported | WASM compatibility |
| Windows | ✅ Supported | TFLite support |
| macOS | ✅ Supported | TFLite support |
| Linux | ✅ Supported | TFLite support |
Getting Started #
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_ml_helper: ^0.0.3
Basic Usage #
import 'package:flutter_ml_helper/flutter_ml_helper.dart';
void main() async {
// Create ML Helper instance
final mlHelper = MLHelper(
enableTFLite: true,
enableMLKit: true,
enableWASM: true, // Enable for web
);
// Load a TFLite model
await mlHelper.tfLite.loadModel('path/to/model.tflite');
// Run inference
final result = await mlHelper.performInference(
input: yourInputData,
modelName: 'model_name',
);
if (result.isSuccess) {
print('Prediction: ${result.topPrediction}');
print('Confidence: ${(result.topConfidence * 100).toStringAsFixed(1)}%');
}
// Clean up
await mlHelper.dispose();
}
TensorFlow Lite Usage #
// Load and run TFLite models
final tfLiteHelper = mlHelper.tfLite;
// Load model
await tfLiteHelper.loadModel('model.tflite');
// Run inference
final result = await tfLiteHelper.runInference(
input: imageData,
modelName: 'model_name',
);
// Get model information
final models = await tfLiteHelper.getAvailableModels();
ML Kit Usage #
// Use ML Kit capabilities
final mlKitHelper = mlHelper.mlKit;
// Text recognition
final textResult = await mlKitHelper.runInference(
input: imageData,
modelName: 'text_recognition',
);
// Face detection
final faceResult = await mlKitHelper.runInference(
input: imageData,
modelName: 'face_detection',
);
Image Processing #
// Preprocess images for ML models
final imageHelper = mlHelper.image;
// Load image (supports JPEG, PNG, BMP, WebP, and HEIC on iOS/Android)
final image = await imageHelper.loadImageFromBytes(imageBytes);
// Preprocess for ML
final processedImage = await imageHelper.preprocessImageForML(
image!,
targetSize: 224,
normalize: true,
convertToGrayscale: false,
);
HEIC Image Support
HEIC format is now supported on iOS and Android. No manual setup required! The platform code is automatically included and registered.
Supported Formats:
- JPEG/PNG/BMP/WebP: Supported on all platforms
- HEIC/HEIF: Supported on iOS 11+ and Android 9+ (automatic)
Dependencies #
- tflite_flutter: ^0.12.0 - TensorFlow Lite support
- google_ml_kit: ^0.20.0 - ML Kit integration
- image: ^4.0.0 - Image processing
- path_provider: ^2.0.0 - File path management
- permission_handler: ^12.0.0 - Permission handling
- path: ^1.0.0 - Path utilities
- http: ^1.0.0 - HTTP client for network requests
Requirements #
- Flutter: 3.32.0+
- Dart: 3.8.0+
- iOS: 11.0+
- Android: API 21+ (API 28+ for HEIC support)
- Web: Modern browsers with WASM support
Configuration #
Android #
Add to android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 21
}
}
iOS #
Add to ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access for ML features</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs photo library access for ML features</string>
Web #
Ensure your web app supports WASM:
<script>
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
</script>
Examples #
Check out the example directory for complete working examples:
- Basic TFLite inference
- ML Kit text recognition
- Image preprocessing
- Cross-platform compatibility
Contributing #
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Support #
- 🐛 Issues: GitHub Issues
- 📖 Documentation: API Reference
- 💬 Discussions: GitHub Discussions
Changelog #
See CHANGELOG.md for a list of changes and version history.
Made with ❤️ by Dhia Bechattaoui