juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
744 stars 444 forks source link

Help implementing multi qr code scan in stepper flutter #999

Open MohdSaadi opened 1 month ago

MohdSaadi commented 1 month ago

Hello , im building a flutter application and i want to scan 2 qr codes in a stepper widget in 2 steps first one is to check the qr code on the voucher and the second is to check the qr code on the vehicle this is an example of the desired app :

WhatsApp Image 2024-03-27 at 10 10 39 PM

also when i took the screenshot the camera stopped i don't know why xD,

this is my widget tree : Step( isActive: _currentStep >= 1, state: _currentStep >= 1 ? StepState.complete : StepState.disabled, title: Text("Scan Qr code of the Voucher"), content: SizedBox( height: MediaQuery.of(context).size.height * 0.5, child: Column( children: [ Expanded( flex: 5, child: MobileScanner( // fit: BoxFit.contain, controller: controller, onDetect: (capture) { _onDetectQRDriver(capture); }, ), ), ], ), ), ), Step( isActive: _currentStep >= 2, state: _currentStep >= 2 ? StepState.complete : StepState.disabled, title: Text("Scan Qr code of the Truck"), content: SizedBox( height: MediaQuery.of(context).size.height * 0.5, child: Column( children: [ Expanded( flex: 5, child: MobileScanner( controller: controller1, onDetect: (capture) { _onDetectQRTruck(capture); }, ), ), ], ), ), ),

  the problem is that when scanning in the first step the on detect function is being called in both widgets so I'm firing 2 functions when the first qr code is scanned . I've tried to implement 2 controller for each qr scanner widget but didn't work,
  can someone please help and guide me on how to implement such flow (1-Scan first qr -> do some verification then proceed to next step (next qr code) and also do some verification....)
  regards
rahul69x commented 1 month ago

Same issue I am facing. Multiple qr not working.

MohdSaadi commented 1 month ago

Same issue I am facing. Multiple qr not working.

I'm thinking of adding a button on each step instead of the qr code widget directly So each button will display a popup that will now contain the qr code widget So we can easily manage the life cycle of it What do you think?

rahul69x commented 1 month ago

I am using QR code in different pages but still same issues. Did you get any chance to resolve the issues?

EArminjon commented 3 weeks ago

Visibility detector + camera.dispose() each time not visible and then create a new controller if visible.