question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to scan once instead of multiple times

See original GitHub issue

Great Work on this package! very helpful, thanks. I have this issue, I have this :

qrCodeCallback: (code) {
        var route = MaterialPageRoute(
          builder: (BuildContext context) => ProductDetails(
                productCode: code,
              ),
        );
        return Navigator.of(context).push(route);
      }

and it builds too many pages. Also, is there a specific example on how to work with the QrCameraState as the GlobalKey? a bit confused on that part.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
rmtmckenziecommented, Dec 6, 2018

I’m eventually going to do a refactor to split the logic of the view and the controller, and when I do I’ll probably put in an option to stop after the first item.

But for now you’re probably better off just using a member variable and setting it to true once you’ve scanned the item, then ignoring it in the callback.

Note that you don’t have to do setState as you’re not changing anything that affects the build funciton.

i.e.

class QrScannerState extends State<QrScanner> {

  bool hasScanned = false;

  qrCodeCallback: (code) {
    if (hasScanned) return;
    hasScanned = true;
    ......
  }
}

And if you actually want to stop/start the camera using GlobalKey, this is how you’d do it. I haven’t included it in the example as it’s actually a pretty messy way of doing things and I’d like to replace it as soon as I get time.

class QrScannerState extends State<QrScanner> {
  GlobalKey<QrCameraState> qrCameraKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return ....
      ...
      QrCamera(
        key: qrCameraKey,
        qrCodeCallback: (code) async {
          qrCameraKey.currentState.stop();
          ...
        }
      ...
  }
}
1reaction
HectorV12commented, Dec 6, 2018

Appreciate the help, thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scanning Documents in Multiple Batches to Create a Single ...
Press the [Scan] button to scan the documents. Press the [Scan] button to scan the document. Repeat steps 8 and 9 until all...
Read more >
C: Multiple scanf's, when I enter in a value for ... - Stack Overflow
scanf("%c") reads the newline character from the ENTER key. When you type let's say 15 , you type a 1 , a 5...
Read more >
How to scan multiple pages into one PDF - Adobe
Learn how to scan multiple pages and merge them into one PDF to save yourself time, money, and an organizational headache.
Read more >
How to scan documents on your iPhone or iPad - Apple Support
You can use the Notes app to scan documents and add signatures on your iPhone or iPad. ... Open Notes and select a...
Read more >
Solved: How to scan multiple pages in one document - 6349901
I downloaded and installed the HPScanExt.msi to be able to scan multiple pages into one PDF document. I executed the app and it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found