flutter_ml_helper 0.0.1
flutter_ml_helper: ^0.0.1 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.
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
- π 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.1
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
final image = await imageHelper.loadImageFromBytes(imageBytes);
// Preprocess for ML
final processedImage = await imageHelper.preprocessImageForML(
image!,
targetSize: 224,
normalize: true,
convertToGrayscale: false,
);
Dependencies #
- tflite_flutter: ^0.10.4 - TensorFlow Lite support
- google_ml_kit: ^0.16.3 - ML Kit integration
- image: ^4.1.7 - Image processing
- path_provider: ^2.1.2 - File path management
- permission_handler: ^11.3.1 - Permission handling
- path: ^1.8.3 - Path utilities
Requirements #
- Flutter: 3.10.0+
- Dart: 3.0.0+
- iOS: 11.0+
- Android: API 21+
- 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 #
- π§ Email: [your-email@example.com]
- π Issues: GitHub Issues
- π Documentation: API Reference
Changelog #
See CHANGELOG.md for a list of changes and version history.
Made with β€οΈ by Dhia Bechattaoui