Git Product home page Git Product logo

flutter_barcode_listener's Introduction

flutter_barcode_listener

Listen for any hardware barcode scanner

Problems with barcode scanning

If you need to get barcode scanned from some hardware barcode scanner you generally have few ways to do it.

  1. implement some text input control (IE. TextEdit), call focus on it and make the scan
  2. listen for some special system event (IE. intent fired from Android service)
  3. listen for raw keyboard events

First aproach is simple, and if you're ok to catch scanned barcodes only when you have focus on text control you're good to go and you don't need this package.

If you however need to somehow get scanned barcodes even when you don't have focus on text input control (or no text input control at all) you're left with two other options.

Listening for special system events (IE. Anroid service intents) is always tied for specific manufacturer/device that usually comes with some kind of SDK you need to implement. This means you're implementation will support listening barcode scannes only for this devices you implemented. Plus, it's not really cross platform friendly

And there's third way, simply listen for raw keyboard events and figure out what's barcode and what's not. Downside of this solution is that you need to figure out what's actual user interaction and what's barcode scan. Upside is it doesn't require any per manufacturer/device implementation and you're pretty much suporting all barcode scanners, including external ones with bluetooth or wifi. And it's cross platform friendly.

Implementation idea

All hardware barcode devices have few things in common

  • they act as a keyboard when barcode is scanned
  • all keyboard events are fired in extremly small time frame (less than 100 ms between each character)
  • barcode is terminated with special character (enter in majority)

So to figure out what is actual barcode and what is simple keyboard event that should be ignored this package uses following logic

  1. listen for physical keyboard raw key up event
  2. filter out only 'REAL' characters (ASCII codes lower than 256, without special characters except enter)
  3. on each new key check if previous key is older than bufferDuration, if it's older clear internal buffer.
  4. check if new key is enter key, if it is call onBarcodeScanned callback and clear buffer
  5. if it's not enter key just append it to internal buffer;

Basically it translates to: if you get bunch of keys comming really fast that end with enter key it's a BINGO.

flutter_barcode_listener's People

Contributors

baghdady92 avatar danielroek avatar eduardotq avatar fuadreza avatar shaxxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flutter_barcode_listener's Issues

android scanning code128 barcode decodes to something different

Hi guys, I'm liking the package so far but I'm struggling with something. While using a CS6080 scanner as an HID keyboard via BT, I'm scanning a CODE128 barcode:
image
The barcode should decode to: 3BE9604F-9E76-42F8-A584-288AD1B7D087

When I scan this barcode on a notes app on both android and iOS it scans the whole barcode correct, so the scanner is working as expected. But on my flutter android app it decodes to: #Be960$f-(e76-4@f8_a584-28*Ad!b&d087
I've tried debugging the package a little and it looks like it might be because of a shift key or something like that.
On iOS however it seems to be working perfectly.

Can you guys possibly help me out? Feel free to reach out so I can help further.

Sticky Keys

Does disabled sticky keys in Linux affect the plugin functionality ?

iOS scanning Problem

When i trying on the ios 12 and 12.5 thats scanning correctly but when i trying on higher than 14 version thats scanning wrong.
Example: My barcode value is "102553" but the output sometimes like "1022553","1025553". They will giving 5 true data each 20-30 scanning. This problem not only for this package i got the that problem on the 'TextField' and 'TextFormField' widgets.

For the android, thats working absolutely correct, no error, no wrong scanning, problem only on ios14 and higher.

My Scanner: Opticon-2006
Note: I try with diffrent scanners but there is no solve.

Not responding at all

I am using trying to run your example in my external handheld device, It is not even populating anything

Does not recognize codes, after the focus has been set to input field

Really nice idea to look at the input speed ;)

But the plugin only works fine for me until I use a text input that get's the focus and the on screen keyboard opens.
After that moment the barcode listener does not recognize the codes any more.

For reprodution I added
Form(key: GlobalKey(), child: TextField(autofocus: false))
to the childs of the BarcodeKeyboardListener.
Firstly the listener reacts on new codes. After the focus has been set to the input field, the barcode listener does not work any more.

How to dispose the scanner

When I want to use textField widget's onEditingComplete callback , using Enter, barcode scanner is working.But I want to dispose it.How can I do it?

Empty barcode

I have a problem with this library, since although it manages to capture the barcodes, most of the attempts, the onBarcodeScanned function returns me an empty barcode, I have tried different EAN 13 barcodes but the result is inconsistent. I also tried to change the bufferDuration property but it doesn't seem to work either.
I'm working on a NQ1000-II android tablet with integrated barcode scanner.

Android: Scanner return nothing in any moment

Code:

    BarcodeKeyboardListener(
    bufferDuration: const Duration(milliseconds: 200),
    onBarcodeScanned: (barcode) {
    if (kDebugMode) {print(barcode);}
      if(barcode.isNotEmpty) {
        searchBarcode(barcode);
      } else{
//restart listener??
        Get.snackbar(
            "Not found",
            "Please restart app",
            icon: const Icon(Icons.error, color: Colors.black),
            snackPosition: SnackPosition.BOTTOM,
            duration: const Duration(seconds: 2)
        );
      }
    }, child: const SizedBox(
    width: double.infinity,
    height: 1),),

How can I restart the listener into the app if i get empty?

Barcode result is empty in Flutter Desktop

Thanks for this wonderful package, however when I tried to work with Flutter Desktop, it doesn't provide any bar code as response. It's empty. Let me know if there's any fixes.

Thanks

Caps Lock error on Android 6

First, very awesome library.
Im using it on a Android device with an external Barcode scanner.
Every time I scan something, im getting this error
Exception caught by services library ══════════════════════════════════ Attempted to send a key down event when no keys are in keysPressed. This state can occur if the key event being sent doesn't properly set its modifier flags. This was the event: RawKeyDownEvent#82bce(logicalKey: LogicalKeyboardKey#00104(keyId: "0x100000104", keyLabel: "Caps Lock", debugName: "Caps Lock"), physicalKey: PhysicalKeyboardKey#70039(usbHidUsage: "0x00070039", debugName: "Caps Lock"), repeat: false) and its data: RawKeyEventDataAndroid#d1f09(flags: 8, codePoint: 0, plainCodePoint: 0, keyCode: 115, scanCode: 58, metaState: 0) 'package:flutter/src/services/raw_keyboard.dart': package:flutter/…/services/raw_keyboard.dart:1 Failed assertion: line 688 pos 7: 'event is! RawKeyDownEvent || _keysPressed.isNotEmpty'

Any idea what the problem could be? Is it a problem of the library or off the scanner?
Im working on Flutter version 3.0.3

Modifier keys detection

OS: Android

If I create a QR code with text MIK.SUZ.SKO.0140.0001, it returns wrong characters ( > instead of . char ). It probably thinks that the SHIFT key is still pressed. For now, I solved the issue by using plainCodePoint instead of codePoint property on RayKeyboardAndroid object and calling uppercase on scanned code.

I don't know how this should be handled, if I use the scanner when focused on some input, it writes correct code.

Need device information

I use multi barcode scanners, so I want to know barcode scanned by what device.
So how I get the device info.
Thank you.

Soft Keyboard

App works great!

We would like to disable the soft keyboard from appearing when we are in a 'scanning' screen using the package to capture barcodes. Can we disable the soft keyboard from appearing within the package when a scan occurs?

Thanks for your time.

Only Works Properly after close and reopening the app

I'm having trouble with my Flutter app's barcode scanning feature on a Zebra MC3300 scanner. The BarcodeScannerField widget only works properly after I close and reopen the app. The first time I use the scanner, the widget doesn't get called at all. But when I restart the app, it magically starts working. Weirdly, this issue doesn't happen on a CipherLabs scanner.

https://stackoverflow.com/questions/76479000/flutter-app-only-works-properly-after-close-and-reopening

connect to external barcode scanner does not work

Hi there,

I'm using a android device which needs to connect an external barcode scanner, the scanner is an scanner box connect to the android PAD, just like the device in supermarket cashier machine computer. tried a long time, but still not work, I wonder if there's special settings need to be done in the scanner side ?

Actually when I tried in emulator, and input characters & enter key in the computer keyboard rapidly, it seems work.

Thanks a lot !

Issue with Keyence reading

Hello,

I tried to use this package for the Keyence device. My app runs at Keyence, but I can't detect scan triggers to use data with your example.
Your idea is exactly what I need, scanning without focusing on TextBox and without a mobile keyboard, just to listen to triggers from the device.
Do you have any idea why this is not working?
Thank you!

I can't see the value of barcode on toast When I scan barcode when keyboard on Korean..

I Want to see the values of barcode immediately on toast message.
But when I use this pack during setting keyboard for Korean,
the value doesn't have korean charaters

ex) value of barcode : 100Barcode-123123

when I scan in Eng -> 100Barcode-123123
but in Korean -> 100-123123

so I inspected the package.

I expect that when I use in iOS , the values return keylabel types.
and keyLabel is defined in doc

'it will be missing special processing for Unicode strings for combining characters and other special characters, and the effects of modifiers.'.

so I don't know what i have to do next.
I need your help guys

Listening unwanted screen

i wrap first screen with barcode listener, but when i navigate to second screen barcode listener is also listening there.

Windows Desktop can not get full code

I have a strange problem, in some Windows systems, the complete barcode cannot always be scanned, and the results in release mode and debug mode are different.
My code is this
BarcodeKeyboardListener( bufferDuration: const Duration(milliseconds: 500), useKeyDownEvent: true, onBarcodeScanned: (barcode) { debugPrint(barcode); if (barcode.length == 12) { barcode = "0" + barcode; } controller.barcode(barcode: barcode); }, child: barcodeList(), )
i have 3 barcode

0755441231925
20147426
3700408421526

in debug mode result
WeChat9588b95f99896733e733ee965ec24f9c

in release mode result
WeChatd242b9c51a207f4067cfda561db339ca

i can't test this plugin

i have zebra android device it has own button to scan barcode. but when i try to scan barcode onBarcodeScanned method does not trigger. what i am doing wrong ?

null return

I have screen with TextEdit.
When enter screen and scan, plugin gives proper barcode on method - is OK
When enter TextEdit and scan, plugin put barcode to TextEdit- is OK
When leave TextEdit (no focus) and scan, plugin returns NULL

Email string @ symbol is returned as "2"

Hey, thanks for this package! I'm scanning 2D barcodes in a variety of formats, QR Codes and Data Matrix (doesn't seem to work in my tests with Aztec format but that's another issue).

I'm generating 2D barcodes with name, age, and email strings. While on the Flutter stable channel, the results were returned wrong nearly every time. But after switching to the Flutter Beta channel the results are correct except for the email string. Specifically the @ symbol is returned as "2".

If I add a barcode with the email [email protected], the plugin returns me2gmail.com every time. I don't know much about this plugin yet, but will see if I can figure it out.

For reference, I'm using a Netum NSL5S USB scanner on a Mac. The scanner works perfectly every time while in a text editing application.

Flutter (Channel beta, 2.9.0-0.1.pre, on macOS 11.2 20D64 darwin-x64, locale en-US)

Scanned barcodes and qr codes is in lowercase

viber_image_2023-06-06_19-28-58-028

values of scanned barcodes and qr codes are all in lower case but when I don't use the package and only used a TextFormField the value is correct, i think it can't detect the if the keyevent has a shift key pressed with other character

(sorry for my bad english 😅)

Remove green border

Hi, Thanks for this library.
In my case, green border appears after scanning the barcode.
Is there any way to remove this?

only reading Lowercase on android.

Scanning QR codes on android is returning the barcodes value, but only in lowercase, I've had a little play but cant seem to find a fix, any ideas?

Null safety

Hi, first of all I would like to congratulate you for this useful package. That said, I would like to ask if you have the intention of to migrate this package to null safety

Q:

Is it possible to have the widget gain focus, or to defocus any other widget(s) once the barcode has been determined?

I have a build that has some input widgets above a visibility widgets and the barcode scanner as used in the example and it works great (windows version) if you click off the other widgets that take input.

However, if focus is in one of those other input fields the also get the barcode as keypresses.

I have tried adding in a 'WidgetsBinding.instance.focusManager.primaryFocus?.unfocus();' call just above the barcode scanner, but it doesn't work.

Any one have a suggestion in how to do this?

issues with windows Scanns

I have made app on macOS and it works as it should be, the scan is perfect, yet once I tried it on windows special characters are not working

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.