Blog for all barKoder's barcode scanner SDK related stuff

Read about barkoder’s latest news, updates and tutorials.

blog-img.webp

Flutter-supported barKoder scanner plugin

 

Introduction

 

We are proud to share some good news. Finally, we can confidently brag that we support Flutter with the mobile barcode scanner SDK by barKoder (Xamarin, and Cordova soon to follow). This is just the first official production version of the software, but it covers the API functions of the native SDK completely. 

To start using the plugin there are a couple of prerequisites. Here's what you need: 

 

How to

 

1. Install the Flutter SDK and setup your environment

 

Depending on the platform you plan to use, this will be different for your use-case, however, flutter covers all major platforms and the installation is pretty straight forward.

 

2. Add the barKoder Flutter plugin to your project

 

There are multiple ways to add the barkoder_flutter package to your Flutter project  (or we should say, at least for now, two ways):

  1. To use the barkoder_flutter package in your Flutter project, you have two options: using the barkoder_flutter package from pub.dev ;
  2. Referencing it from a local path.

 

To use the package from pub.dev, add the package name and version to your project's dependencies - pubspec.yaml file as follows:

dependencies:
              flutter:
                sdk: flutter
            
              barkoder_flutter: <package version>
          
 

If you prefer to use a local package, download the package from https://barkoder.com and set the package path in your project's dependencies - pubspec.yaml file as follows:

 dependencies:
                 flutter:
                   sdk: flutter
               
                 barkoder_flutter:
                   path: <package local path>
          
 

3. Install dependencies

To install the specified dependencies in your Flutter project, run the following command in the terminal:

flutter pub get

This command will fetch and install the required dependencies for your project.

 

4. Import package

Import the barkoder_flutter package in your project with:

 import 'package:barkoder_flutter/barkoder_flutter.dart';
          
 

 

5. BarkoderView

At this stage, assuming that the barkoder_flutter package is installed and imported into your project, you can proceed to add the BarkoderView widget to your layout. Make sure to set the licenseKey parameter and the onBarkoderViewCreated callback. Here's an example of how to accomplish this:

 @override
             Widget build(BuildContext context) {
               return Scaffold(
                 ...,
                 body: BarkoderView(
                           licenseKey: 'KEY',
                           onBarkoderViewCreated: _onBarkoderViewCreated),
                 ...
               );
          
 

The license key is a string composed of alphanumeric characters, meaning it can contain both letters (A-Z, a-z) and numbers (0-9). See section Section 8 to learn how to get a valid license.

 

6. Ready to Scan Event

Inside the _onBarkoderViewCreated callback function the SDK is fully initialized and ready for configuration or to start the scanning process

 void _onBarkoderViewCreated(barkoder) {
             _barkoder = barkoder;
             _barkoder.setBarcodeTypeEnabled(BarcodeType.qr, true);
             _barkoder.setRegionOfInterestVisible(true);
           
             ...
           }
           void _scanPressed() {
             _barkoder.startScanning((result) {
               // The result from successful scan is received here
             });
           }
          
 

For the complete usage of the barkoder_flutter plugin please check our sample.

 

7. Make sure you have the necessary permissions, such as camera permissions, configured in your app for the barcode scanner to function properly.   
 

  1. For Android, the permission is set in the manifest from the plugin. Here's an example of how to add the camera permission:
  • Open the AndroidManifest.xml file located in the android/app/src/main directory of your Flutter project.
  • Locate the <manifest> tag and add the following permission declaration inside it:
uses-permission android:name="android.permission.CAMERA" />

   

   2. For iOS you need to specify camera permission in Info.plist file inside your project

 <key>NSCameraUsageDescription</key>
<string>Camera permission</string>

Once you've added the camera permission your app should prompt the user for camera access when needed for barcode scanning.

 

8. Licensing 

The mobile barcode reader SDK by barKoder is designed to allow barcode scanning even without a valid license. However, to maintain security and privacy, all scanning results are obfuscated with (*) asterisk characters. In order to alleviate that you can either get a trial license (to test the software out) or procure a production license that can be used within a production app.

 

Flutter's documentation is also available on our docs page

 

Latest Barcode Scanner SDK Articles, Tutorials, and News