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

Pub Version Flutter Version Dart Version License

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 #

  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
34
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

Documentation

API reference

License

MIT (license)

Dependencies

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

More

Packages that depend on flutter_ml_helper