Quick Start Guide
July 24, 2026 ยท View on GitHub
Get YOLO object detection running in your Flutter app in under 2 minutes! โก
๐ฏ Goal
By the end of this guide, you'll have a working Flutter app that can detect objects in images using YOLO.
๐ Prerequisites
- โ Flutter SDK installed
- โ Android/iOS device or emulator
- โ 2 minutes of your time
๐ Step 1: Create New Flutter App
flutter create yolo_demo
cd yolo_demo
๐ฆ Step 2: Add YOLO Plugin
Add to pubspec.yaml:
Package: https://pub.dev/packages/ultralytics_yolo
dependencies:
flutter:
sdk: flutter
ultralytics_yolo: ^0.5.1
image_picker: ^1.2.1 # For image selection
Install dependencies:
flutter pub get
๐ฏ Step 3: Add a model
The simplest path is to use an official model ID and let the plugin download it automatically. Call YOLO.officialModels() to see which IDs are available on the current platform.
final yolo = YOLO(modelPath: 'yolo26n');
Custom local models are still supported:
- iOS: drag
.mlpackageor.mlmodelinto ios/Runner.xcworkspace, or bundle.mlpackage.zipin Flutter assets - Android native assets: place
.tflitefiles in android/app/src/main/assets/ - Flutter assets: place
.tfliteon Android or.mlpackage.zipon iOS inassets/models/and use that asset path directly
Task and labels are auto-detected from the model's embedded metadata. If your custom model has no task in its metadata, pass it explicitly.
Android inference runs on LiteRT 2.x with an automatic GPU โ CPU accelerator ladder; iOS uses Core ML. Official int8 YOLO26 TFLite assets can compile on the LiteRT GPU path on supported devices, but int8 GPU coverage depends on the device driver and graph; graphs the GPU cannot compile fall back to CPU. non-end-to-end exports are useful for GPU benchmarking (the GPU delegate runs them in FP16):
YOLO("yolo26n.pt").export(format="litert", nms=False, end2end=False, imgsz=640)
# Classification models use imgsz=224.
โก Step 4: Minimal Detection Code
Replace lib/main.dart with this complete working example:
import 'package:flutter/material.dart';
import 'package:ultralytics_yolo/ultralytics_yolo.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
void main() => runApp(YOLODemo());
class YOLODemo extends StatefulWidget {
@override
_YOLODemoState createState() => _YOLODemoState();
}
class _YOLODemoState extends State<YOLODemo> {
YOLO? yolo;
File? selectedImage;
List<dynamic> results = [];
bool isLoading = false;
@override
void initState() {
super.initState();
loadYOLO();
}
Future<void> loadYOLO() async {
setState(() => isLoading = true);
yolo = YOLO(
modelPath: 'yolo26n',
);
await yolo!.loadModel();
setState(() => isLoading = false);
}
Future<void> pickAndDetect() async {
final picker = ImagePicker();
final image = await picker.pickImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
selectedImage = File(image.path);
isLoading = true;
});
final imageBytes = await selectedImage!.readAsBytes();
final detectionResults = await yolo!.predict(imageBytes);
setState(() {
results = detectionResults['boxes'] ?? [];
isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('YOLO Quick Demo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (selectedImage != null)
Container(
height: 300,
child: Image.file(selectedImage!),
),
SizedBox(height: 20),
if (isLoading)
CircularProgressIndicator()
else
Text('Detected ${results.length} objects'),
SizedBox(height: 20),
ElevatedButton(
onPressed: yolo != null ? pickAndDetect : null,
child: Text('Pick Image & Detect'),
),
SizedBox(height: 20),
// Show detection results
Expanded(
child: ListView.builder(
itemCount: results.length,
itemBuilder: (context, index) {
final detection = results[index];
return ListTile(
title: Text(detection['class'] ?? 'Unknown'),
subtitle: Text(
'Confidence: ${(detection['confidence'] * 100).toStringAsFixed(1)}%'
),
);
},
),
),
],
),
),
),
);
}
}
๐โโ๏ธ Step 5: Run Your App
flutter run
๐ That's It!
You now have a working YOLO object detection app! The app will:
- Load the YOLO model when it starts
- Let you pick an image from your gallery
- Detect objects in the selected image
- Show results with class names and confidence scores
๐ Next Steps
Add Real-time Camera
Want real-time detection? Add the YOLOView widget:
import 'package:ultralytics_yolo/ultralytics_yolo.dart';
// Replace the Column with:
YOLOView(
modelPath: 'yolo26n',
onResult: (results) {
print('Detected ${results.length} objects');
},
)
Dynamic Model Switching
Switch models without restarting the camera:
final controller = YOLOViewController();
YOLOView(
modelPath: 'yolo26n', // Initial model
controller: controller,
onResult: (results) {
print('Detected ${results.length} objects');
},
)
// Later, switch to another official model or a custom export
await controller.switchModel('assets/models/custom.tflite', YOLOTask.detect);
๐ฏ Multi-Instance Quick Example
Want to run multiple models? Try this:
// Create two YOLO instances
final detector = YOLO(
modelPath: 'yolo26n',
useMultiInstance: true, // Enable multi-instance
);
final classifier = YOLO(
modelPath: 'assets/models/yolo26n-cls.tflite',
task: YOLOTask.classify,
useMultiInstance: true,
);
// Load both models
await detector.loadModel();
await classifier.loadModel();
// Run both on the same image
final detections = await detector.predict(imageBytes);
final classifications = await classifier.predict(imageBytes);
๐ ๏ธ Troubleshooting
App crashes on startup?
- Make sure the model file exists in the right place
No detections found?
- Try a different image with clear objects
- Check model file is not corrupted
- Verify model matches the task type
Build errors?
- Run
flutter clean && flutter pub get - Check minimum SDK versions in installation guide
Slow detections on Android?
- Keep
useGpu: trueand verify LiteRT delegate placement in device logs; benchmark non-end-to-end exports (run in FP16 on the GPU delegate) when comparing GPU paths.
๐ Learn More
Now that you have YOLO working, explore more features:
- ๐ Usage Guide - Advanced patterns and examples
- ๐ง API Reference - Complete API documentation
- ๐ Performance - Optimization tips
- ๐ ๏ธ Troubleshooting - Common issues and solutions
๐ก Pro Tips
- Start small: Use
yolo26nfor development, then move up in size if needed - Test on device: Emulators don't show real performance
- Monitor memory: Watch usage when running multiple instances
- Cache models: Keep loaded models in memory for better performance
๐ Congratulations! You've successfully integrated YOLO into your Flutter app. Ready to build something amazing? ๐