Below is a complete step-by-step guide to create a QR Code Scanner App using Flutter, suitable for beginners and also good enough for a production-ready demo ๐
(Iโll keep it simple and clean, just like your previous Flutter learning topics.)
๐น Step 1: Create a New Flutter Project
flutter create qr_scanner_app
cd qr_scanner_app
flutter run
๐น Step 2: Add Required Dependencies
Open pubspec.yaml and add:
dependencies:
flutter:
sdk: flutter
mobile_scanner: ^5.0.0
Then run:
flutter pub get
๐ mobile_scanner is fast, stable, and supports Android & iOS.
๐น Step 3: Android Permissions
๐ AndroidManifest.xml
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA"/>
Inside <application> tag:
android:hardwareAccelerated="true"
๐น Step 4: iOS Permissions
๐ Info.plist
ios/Runner/Info.plist
<key>NSCameraUsageDescription</key>
<string>Camera permission is required to scan QR codes</string>
๐น Step 5: Main App Code
๐ main.dart
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'QR Scanner',
home: const QRScannerPage(),
);
}
}
class QRScannerPage extends StatefulWidget {
const QRScannerPage({super.key});
@override
State<QRScannerPage> createState() => _QRScannerPageState();
}
class _QRScannerPageState extends State<QRScannerPage> {
String scannedResult = "Scan a QR Code";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("QR Scanner App"),
centerTitle: true,
),
body: Column(
children: [
Expanded(
flex: 4,
child: MobileScanner(
onDetect: (barcode) {
final String? code = barcode.barcodes.first.rawValue;
if (code != null) {
setState(() {
scannedResult = code;
});
}
},
),
),
Expanded(
flex: 1,
child: Container(
width: double.infinity,
color: Colors.black,
alignment: Alignment.center,
child: Text(
scannedResult,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
textAlign: TextAlign.center,
),
),
),
],
),
);
}
}
๐น Step 6: Run the App
flutter run
๐ฑ Point your camera at any QR code โ result appears instantly.
๐น Features You Can Add (Next Level ๐)
โ Flashlight ON/OFF
โ Scan only once (prevent duplicate scans)
โ Open scanned URL in browser
โ Save scanned history
โ Add Clean Architecture + BLoC (like your previous projects)
๐น Flashlight Button Example (Optional)
MobileScannerController controller = MobileScannerController();
IconButton(
icon: const Icon(Icons.flash_on),
onPressed: () {
controller.toggleTorch();
},
),
๐น Common Errors & Fixes
โ Camera not opening
โ Check permissions in AndroidManifest & Info.plist
โ App crashes on scan
โ Use null check for barcode value
๐น Final Output
โ Fast QR scanning
โ Android & iOS supported
โ Minimal & clean UI
โ Production ready base