Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter qr bar scanner

a full screen scanner for scanning qr code and barcode using google’s mobile vision api

usage

import 'package:flutter/material.dart';
import 'package:flutter_qr_bar_scanner/qr_bar_scanner_camera.dart';

void main() {
  runapp(myapp());
}

class myapp extends statelesswidget {
  @override
  widget build(buildcontext context) {
    return materialapp(
      title: 'flutter qr/bar code reader',
      debugshowcheckedmodebanner: false,
      theme: themedata(
        primaryswatch: colors.blue,
      ),
      home: myhomepage(title: 'flutter qr/bar code reader'),
    );
  }
}

class myhomepage extends statefulwidget {
  myhomepage({key? key, this.title}) : super(key: key);
  final string? title;
  @override
  _myhomepagestate createstate() => _myhomepagestate();
}

class _myhomepagestate extends state<myhomepage> {
  string? _qrinfo = 'scan a qr/bar code';
  bool _camstate = false;

  _qrcallback(string? code) {
    setstate(() {
      _camstate = false;
      _qrinfo = code;
    });
  }

  _scancode() {
    setstate(() {
      _camstate = true;
    });
  }

  @override
  void initstate() {
    super.initstate();
    _scancode();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  widget build(buildcontext context) {
    return scaffold(
      appbar: appbar(
        title: text(widget.title!),
      ),
      body: _camstate
          ? center(
              child: sizedbox(
                height: 1000,
                width: 500,
                child: qrbarscannercamera(
                  onerror: (context, error) => text(
                    error.tostring(),
                    style: textstyle(color: colors.red),
                  ),
                  qrcodecallback: (code) {
                    _qrcallback(code);
                  },
                ),
              ),
            )
          : center(
              child: text(_qrinfo!),
            ),
    );
  }
}


the qrcodecallback can do anything you’d like, and wil keep receiving qr/bar codes
until the camera is stopped.

there are also optional parameters to qrscannercamera.

fit

takes as parameter the flutter boxfit.
setting this to different values should get the preview image to fit in
different ways, but only boxfit = cover has been tested extensively.

notstartedbuilder

a callback that must return a widget if defined.
this should build whatever you want to show up while the camera is loading (which can take
from milliseconds to seconds depending on the device).

child

widget that is shown on top of the qrscannercamera. if you give it a specific size it may cause
weird issues so try not to.

key

standard flutter key argument. can be used to get qrscannercamerastate with a globalkey.

offscreenbuilder

a callback that must return a widget if defined.
this should build whatever you want to show up when the camera view is ‘offscreen’.
i.e. when the app is paused. may or may not show up in preview of app.

onerror

callback for if there’s an error.

‘formats’

a list of supported formats, all by default. if you use all, you shouldn’t define any others.

these are the supported types:

  all_formats,
  aztec,
  code_128,
  code_39,
  code_93,
  codabar,
  data_matrix,
  ean_13,
  ean_8,
  itf,
  pdf417,
  qr_code,
  upc_a,
  upc_e

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.