Migration to Flutter Guide
Discover our battle-tested 21-step framework for a smooth and successful migration to Flutter!
Jump to:

Barcode scanning in Flutter

What is barcode scanning in Flutter?

Barcode scanning in Flutter allows an app to read QR codes and barcodes using the device camera and convert them into structured data (text, IDs, URLs). Flutter does not provide this feature out of the box, so native integrations are required via plugins.

Key characteristics

  • Requires runtime camera permission
  • Uses native APIs under the hood
  • Performance depends on hardware and lighting
  • Behavior differs slightly between Android and iOS

Why does barcode scanning matter in Flutter app development?

Barcode scanning is commonly used in:

  • inventory and warehouse apps
  • e-commerce product lookup
  • ticketing and event check-in
  • payments and coupons

It enables fast, accurate input without manual typing.

How does barcode scanning work?

Modern Flutter barcode scanners work by:

  • accessing the device camera
  • streaming frames in real time
  • decoding barcodes using native engines (e.g. ML Kit)
  • returning results asynchronously to Dart

The camera lifecycle is managed by a controller, which must be properly disposed of to avoid resource leaks.

Example of Flutter barcode scanner

A modern and actively maintained solution is mobile_scanner.

Simplified usage:

MobileScanner(
onDetect: (barcode, args) {
final value = barcode.rawValue;
if (value != null) {
print(value);
}
},
)

This widget internally manages the camera stream and barcode detection. In real apps, you should stop scanning after a successful read to avoid duplicates.

When to use barcode scanning?

Barcode scanning is particularly useful whenever your application needs to bridge the physical and digital worlds. It is ideal for apps where users interact with physical products, tickets, or documents, and where manually entering codes would be slow, error-prone, or impractical. Retail, inventory management, and logistics apps often rely on scanning to ensure speed and accuracy, enabling real-time updates of stock levels, price verification, or order fulfillment.

It is also highly relevant when the data already exists in a machine-readable format, such as QR codes, UPC codes, or other standard barcodes. This allows for immediate data retrieval without requiring users to type or search manually. Barcode scanning can enhance workflows in event management, loyalty programs, or payment systems, where fast and reliable identification of items or users improves the overall experience.

In addition, scanning can be combined with business logic, like automatically fetching product details, validating tickets, or logging attendance. When designed correctly, barcode scanning becomes a natural extension of the app interface, reducing friction and improving operational efficiency while maintaining a consistent and responsive user experience.

Flutter barcode scanner SDK options

Common choices:

  • mobile_scanner – lightweight, actively maintained, ML Kit–based
  • ai_barcode_scanner – higher-level abstraction with UI helpers
  • Commercial SDKs – advanced features, licensing required

Avoid deprecated packages like barcode_scan or barcode_scan2.

Best practices for barcode scanners in Flutter

  • Always explain why camera access is needed
  • Add NSCameraUsageDescription on iOS
  • Dispose of camera resources when leaving the screen
  • Stop scanning after the first valid result
  • Test only on real devices

Common mistakes to avoid

  • Using deprecated scanner libraries
  • Forgetting NSCameraUsageDescription in Info.plist (causes iOS crash)
  • Assuming scanning works on emulators
  • Not disposing of the camera controller
  • Ignoring user permission denial