Is there a way to scan barcodes in Flutter?

22,449

Solution 1

I've previously had a similar problem, and after searching as you did I didn't find a whole lot. I decided that the best approach would be to write a plugin myself... so shameless plug for my plugin here =D, not that I benefit from anyone else using it at all.

You can see it here. However, I haven't had time to document it, test it all that extensively, or publish it properly on Pub. So your mileage may vary. It should however work on android 4.4+ (and maybe below), and iOS devices that flutter supports. I also haven't tested it in conjunction with the Camera plugin but I don't see why it would have a problem with it.

It takes a different approach than most of the other qr code plugins; instead of making an android or iOS window, doing the scan, then returning to flutter, it uses flutter's texture rendering capabilities to have the camera render directly into flutter.

A few more things to consider are that it uses the Google Mobile Vision SDK with the applicable licensing and capabilities that comes along with that (and requires a recent version of Play Services on Android); and that it currently only supports the most basic extraction of information from barcode scans - I only needed the raw text out so that's all I did.

To use it, add this to your pubspec.yaml:

dependencies:
  qr_mobile_vision: '^0.0.7'

And implement as follows:

import 'package:qr_mobile_vision/QrCamera.dart';

...

new Container(
  constraints: new BoxConstraints.loose(
  new Size(cameraSize, cameraSize)),
  child: new QrCamera(
    qrCodeCallback: (code) {
      print(code);
    }
  ),
)

I do plan on finishing documentation/testing/etc eventually, but you're welcome to try it out in the meantime. If you decide to use it and need a feature it doesn't support I may be able to help implement it... but PRs are welcome and encouraged!

UPDATE: this does include Barcode support now. You can pass in which types of QR code / Barcode you want to support when you instantiate QrCamera. It defaults to all, which takes more processing so if you're after a certain type it's recommended that you pass it in.

Solution 2

I'm working on something currently as a companion to my QR generation plugin (https://github.com/lukef/qr.flutter) but I don't have a specific timeline, unfortunately.

My plan is to use the Texture object and hookup a camera (or fork / use the camera plugin) and then use the Google Vision API (https://developers.google.com/vision/android/barcodes-overview).

It should be decently trivial, I just need to find the time. Either way, that was the plan if you want to do it :)

Share:
22,449

Related videos on Youtube

Nato Boram
Author by

Nato Boram

Updated on October 12, 2020

Comments

  • Nato Boram
    Nato Boram over 3 years

    Basically, I'm making an app that scans a QR code to connect to a server. Then, the app will scan the barcode of products and take pictures of the item and send them to the server. My question is the following :

    Is there a Flutter plugin to scan QR codes and barcodes that doesn't enter in conflict with image_picker?

    Here's what I found so far.

    I appreciate any help you can provide. Thanks!


    Update

    The issue with barcode_scan was resolved. I ended up using this one since it's faster than the accepted answer and its issues got resolved rather quickly. Be aware that its behaviour on iOS is modified by Apple, so you might get different results with checksum numbers or something.

    • Amol Gangadhare
      Amol Gangadhare about 5 years
    • Lynn
      Lynn almost 5 years
      The issue with barcode_scan this post mentions has been closed.
    • Nato Boram
      Nato Boram almost 5 years
      @Lynn You are right. The Flutter ecosystem changed so drastically that this whole thread is embarrassingly outdated and will probably actively hinder anyone stumbling upon this question. It should probably be closed or something.
    • Roland van der Linden
      Roland van der Linden about 3 years
      Sadly, the barcode_scan dependency is now discontinued.
  • rmtmckenzie
    rmtmckenzie about 6 years
    I've implemented basically what you're talking about @ github.com/rmtmckenzie/flutter_qr_mobile_vision. If you have time to contribute, you're welcome to use that as a base of course, and PRs are welcome. Once I document it & clean it up a bit more I'm planning on releasing it on Pub...
  • rmtmckenzie
    rmtmckenzie about 6 years
    Oops - I merged the static branch to master and then forgot to update this to reflect that. I've updated it (and thanks @NatoBoram for pointing that out)
  • Saman
    Saman almost 6 years
    I updated dependencies but the .../QrCamera.dart package is not existing. @rmtckenzie
  • rmtmckenzie
    rmtmckenzie almost 6 years
    @SaMiGiMiX did you depend on it with the github url or pub? This answer is a bit out of date - the released version is at qr_mobile_vision: '^0.0.7' now and a few people are using it so it should work. Try adding it to your pubspec then running flutter packages get.
  • Saman
    Saman almost 6 years
    the correct package is "qr_mobile_vision/qr_camera.dart".
  • Saman
    Saman almost 6 years
    thanks for creating this package, but is there a way to insert delay for each scan and then callback ?
  • rmtmckenzie
    rmtmckenzie almost 6 years
    @samigimix I'm not sure exactly what you mean - can you elaborate and maybe provide an example? And the GitHub project would probably be a better place for that than here.
  • Saman
    Saman almost 6 years
    rmtmckenzie yes I wroted my question in your package's GitHub page.
  • mauriii
    mauriii almost 5 years
    Great package! Of course needs some work, but it does what it says. I do recommend adding more comment documentation in the code.
  • user2233706
    user2233706 about 4 years
    Why is the camera so dark compared to barcode_scan?
  • Mateen
    Mateen about 4 years
    I'm getting this Firebase error, even I'm not using anywhere. PlatformException(error, Default FirebaseApp is not initialized in this process com.mateen.restpool. Make sure to call FirebaseApp.initializeApp(Context) first., null)
  • Kamlesh
    Kamlesh over 3 years
    how can we know that selected image from gallery is a valid QR code image or not?
  • Cassio Seffrin
    Cassio Seffrin over 3 years
    @Kamlesh this is not the proposal of the libraries I mentioned above. But you can read QR code from device gallery using this package pub.dev/packages/qr_code_tools