QR scanning in Flutter is commonly used for login flows, payments, event check-ins, and device pairing. Flutter does not provide a built-in QR scanning API, so this functionality is implemented using plugins that integrate with native camera and barcode detection frameworks.
A QR scanner in Flutter is a plugin-based solution that:
On Android and iOS, QR scanners rely on native camera APIs and platform barcode detectors. On the web, scanning depends on browser camera access and has more limitations.
Most Flutter QR scanning packages focus on QR codes only. Support for other barcode formats depends on the chosen plugin.
A minimal example using mobile_scanner:
final controller = MobileScannerController();
@override
void initState() {
super.initState();
controller.start();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
MobileScanner(
controller: controller,
onDetect: (barcode, args) {
final String? code = barcode.rawValue;
if (code == null) return;
debugPrint('Scanned QR code: $code');
},
);This widget opens the camera and continuously scans for QR codes until you stop or dispose of the controller.
A common beginner confusion is expecting the scan result to be a simple string.
In reality, the scanner returns an object (often called Barcode). This object contains metadata about the scan. The actual decoded content is usually stored in fields like rawValue or displayValue.
If you try to print or display the entire object, you will often see something like Instance of 'Barcode'. To get the real content, always extract the string value explicitly.
QR scanners may detect the same code multiple times while it stays in view.
In real applications, you usually:
Without this, navigation or API calls may trigger multiple times.
QR scanning requires explicit camera permissions on each platform.
On iOS, camera access must be declared in Info.plist using NSCameraUsageDescription.
The value of this key is shown directly to the user in the system permission dialog, so it must clearly explain why the camera is needed. Add a description like this "The app needs camera access to scan QR codes on tickets."
Using vague or placeholder text (for example "test" or "camera access") is a common reason for App Store rejection.
On Android, camera permission must be declared in AndroidManifest.xml.
In addition:
Your app should always handle the case where camera permission is not granted and show a clear fallback or explanation.
A very common issue is the camera freezing after navigating away and back to the scanner screen. This usually happens when the scanner controller is not properly managed.
The correct pattern is:
initState.dispose.Camera resources must be released when the widget is removed from the tree. Failing to do this often results in a black or frozen camera preview when returning to the screen.
QR scanning on Flutter Web works differently than on mobile.
Important limitations:
For web apps, QR scanning should be treated as a best-effort feature rather than a guaranteed flow.
Typical beginner issues include:
6 min • Mar 17, 2022
As the number of smart devices grows, so does the need to control them. Bluetooth Low Energy seems to be the best choice for connecting devices due to its low power needs. By reading this article you will find out how to begin developing a BLE app in Flutter.
20 min. • Feb 9, 2024
In a recent project, we embarked on the exciting task of enhancing an existing app with dynamic social media elements. Choosing Stream as our ally, we navigated through challenges and came up with strategies that helped us overcome them, resulting in the successful delivery of a news feed feature. Read our complex article.
16 min. • Jul 17, 2023
Building an enterprise-scale application in Flutter, as in any other framework, requires a specific approach toward organizing the team and the code they create. This comprehensive tech article explains how to approach such a large-scale project.