On this page

Stuck? Open a support ticket and the barKoder team will help. Open a ticket

Flutter Installation

Before you start #

Prepare environment #

Install Flutter SDK and set up your environment. A new app: flutter create my_app, then cd my_app (the steps below are in that folder).

1. Add the package #

Add the package #

Add the package from pub.dev, or from a folder you downloaded.

To use the package from pub.dev, add the package name and version to the dependencies in your project's pubspec.yaml (or run flutter pub add barkoder_flutter, which adds the latest version):

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

For a local package, download it from Downloads in the barKoder Developer Portal and give its path instead:

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

Install dependencies #

Run flutter pub get in the app's folder to fetch the package.

With barkoder_flutter 1.7.2, the Android build of a new app (Flutter 3.47) stops at checkDebugAarMetadata (":barkoder_flutter is currently compiled against android-31"): the plugin compiles against Android API 31, and the AndroidX libraries a Flutter app uses need 34 or later. Add these lines at the top of android/build.gradle.kts; they compile the plugin against API 36, as the app is:

Kotlin
subprojects {
    afterEvaluate {
        if (name == "barkoder_flutter") {
            extensions.configure<com.android.build.api.dsl.LibraryExtension>("android") {
                compileSdk = 36
            }
        }
    }
}

Import package #

Import it in the file that shows the scanner:

Dart
import 'package:barkoder_flutter/barkoder_flutter.dart';

2. Allow the camera #

Camera permissions #

The scanner needs the camera. On Android the plugin's manifest asks for it. On iOS, add the camera key to ios/Runner/Info.plist:

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

3. Add the scanner view #

BarkoderView #

Put BarkoderView in your layout, with your license key and an onBarkoderViewCreated callback. The button calls _scanPressed (step 5):

Dart
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: BarkoderView(
      licenseKey: 'KEY',
      onBarkoderViewCreated: _onBarkoderViewCreated,
    ),
    floatingActionButton: FloatingActionButton(
      onPressed: _scanPressed,
      child: const Icon(Icons.qr_code_scanner),
    ),
  );
}

4. Set the license key and barcode types #

Licensing #

Without a valid license key the SDK still scans, but each result starts with (Unlicensed) and part of its data is replaced with dots. Get a free trial key on the trial page: choose Native or WASM and enter your app ID (for the Web SDK, your domain). A trial key lasts 30 days, for up to 25 devices, one per app ID. For a production license, request a quote. By using the SDK you agree to the End User License Agreement.

The key goes in the licenseKey of BarkoderView (step 3). The barcode types are turned on in _onBarkoderViewCreated, in the code of step 5.

5. Start scanning and read results #

Start scanning #

When _onBarkoderViewCreated is called, the SDK is ready: keep the instance, turn on the barcode types and change other settings there. _scanPressed starts scanning, and each result comes to its callback. Both methods go in the same State class:

Dart
late Barkoder _barkoder;

void _onBarkoderViewCreated(Barkoder barkoder) {
  _barkoder = barkoder;

  _barkoder.setBarcodeTypeEnabled(BarcodeType.qr, true);
  _barkoder.setRegionOfInterestVisible(true);

  // other settings
}

void _scanPressed() {
  _barkoder.startScanning((result) {
    // The result from successful scan is received here
    print(result.decoderResults[0].textualData);
  });
}

The General example has a whole app.