flutter_ml_helper 0.1.0 copy "flutter_ml_helper: ^0.1.0" to clipboard
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 #

Pub Version CI Flutter Version Dart Version License

Easy integration with TensorFlow Lite and ML Kit for Flutter applications. Supports all 6 platforms with WASM compatibility.

Demo #

Text Recognition Demo Face Detection Demo TFLite Inference 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 #

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Support #

Changelog #

See CHANGELOG.md for a list of changes and version history.


Made with ❤️ by Dhia Bechattaoui

1
likes
160
points
229
downloads

Publisher

verified publisherbechattaoui.dev

Weekly Downloads

Easy integration with TensorFlow Lite and ML Kit for Flutter applications. Supports all 6 platforms with WASM compatibility.

Repository (GitHub)
View/report issues

Topics

#flutter #machine-learning #tensorflow-lite #ml-kit #cross-platform

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

flutter, google_ml_kit, http, image, path, path_provider, permission_handler, tflite_flutter

More

Packages that depend on flutter_ml_helper

Packages that implement flutter_ml_helper