Flutter apps are really good at performance and using Flutter we can build highly scaled apps. Flutter is found to be really sensational at various native features and services. Camera access and scanning are those native features that most of the highly scaled application needs. Barcodes and QR Codes are the official codes for product recognition and are used in various industrial aspects as well. So, working with barcodes and QR codes can be really handy for the management of data by means of unique codes.

Flutter framework helps us working with codes as it is having a package called barcode_scan. You are just required to add this package to your project by adding below line to your pubspec.yaml file.

pubspec.yaml

After that you should type the command below in your terminal:

flutter pub get

Now, create a new file home.dart in the lib folder of the project and write the below code inside that file.

home.dart file

Now, we are required to create a new file scan.dart inside the lib folder and create a StatefulWidget named ScanScreen like given below:

StatefulWidget ScanScreen

The build() of the _ScanScreen() class will be defined like below:

build() method for Stateful widget

In the above build method() for StatefulWidget, we have defined a RaisedButton() widget in the center and the UI, we are going to get will be:

Screenshot of UI

In the above code, we have referred the scan method in the onPressed() method of the RaisedButton() which will be defined like:

In the above scan() method, we have called the scan method from the BarcodeScanner class which is defined in the barcode_scan package. After calling that method, we are storing the value of scanned code to a variable and using setState() method of StatefulWidget, we are initialising that variable. And accordingly the error handling is done.

At last after all thecode in place, we will be seeing the camera screen after clicking the button: