This content originally appeared on DEV Community and was authored by DEV Community
In this post, we'll be using package barcode_scan2: ^4.2.0
to scan the QR Code.
Add Package to the Pubspec.yaml
dependencies:
flutter:
sdk: flutter
barcode_scan2: ^4.2.0
Allow Access to Camera in Android and IOS
To use the QR Scanner, we have to allow the app to access the camera phone so at first we'll add the code to Android and IOS Folder,
go to:
path: android/app/src/main/AndroidManifest.xml
and Add this line of code before application
...
<uses-permission android:name="android.permission.CAMERA" />
<application ...
and Save.
Incase you get the multidex error
please add
path: android/app/src/build.gradle
---------------
defaultConfig {
....
multiDexEnabled true
}
...
...
...
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Now Moving on to the IOS Part
path: ios/Runner/Info.plist
add these code
<dict>
<key>NSCameraUsageDescription</key>
<string>Camera permission is required for barcode scanning.</string>
</dict>
Create QR Code Dart
Once you have done that, now create a QRScannerScreen.dart file and add a button in the container or center
TextButton(
child: Text("Scan Now"),
onPressed: (){
var result = await BarcodeScanner.scan(); //barcode scanner
print(result.type); // The result type (barcode, cancelled, failed)
print(result.rawContent); // The barcode content
print(result.format); // The barcode format (as enum)
print(result.formatNote);
}
)
Use Barcode: BarCode Scan 2
This content originally appeared on DEV Community and was authored by DEV Community
DEV Community | Sciencx (2022-03-09T17:20:56+00:00) How to creat QR Code Scanner in Flutter?. Retrieved from https://www.scien.cx/2022/03/09/how-to-creat-qr-code-scanner-in-flutter/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.