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
891 stars 515 forks source link

ScanWindow not shows #1043

Open JP3871 opened 6 months ago

JP3871 commented 6 months ago

mobile_scanner 4.0.1 Flutter 3.16

Hi, can someone tell me why my aera scan is not showing? I want to display the aera after my first Button I missed something? Below, my code

Thanks a lot

image

image

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Scan Stock')), backgroundColor: Colors.black, body: // Column( children: [ // const SizedBox(height: 10), ElevatedButton( style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.orangeAccent, fixedSize: const Size(350, 60), ), onPressed: () { }, child: const Text( "MES ARTICLES CODE-BARRE", style: TextStyle(color: Colors.black, fontSize: 20), ), ), // const SizedBox(height: 10), MobileScanner( controller: scanController, fit: BoxFit.contain, scanWindow: Rect.fromCenter( center: MediaQuery.sizeOf(context).center(Offset.zero), width: 500, height: 200), onDetect: (BarcodeCapture barcodes) {}), // const SizedBox(height: 15), // aligner btn PAUSE et SCANNER = row mais "sans coupure" Wrap(children: [ // const SizedBox(height: 20), ElevatedButton( style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.yellow), onPressed: () { setState(() { _codeCB = 'ATTENTE SCAN'; _visible = false; scanController.stop(); }); }, child: const Text( " PAUSE ", style: TextStyle(color: Colors.black), ), ), // const Text(' '), ElevatedButton( style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: Colors.blue), onPressed: () { setState(() { _codeCB = 'ATTENTE SCAN'; _visible = true; scanController.start(); }); // }, child: const Text(" SCANNER "), ), ]), // // message du scan : attente scan const SizedBox(height: 20), Container( height: 65.0, width: double.infinity, color: Colors.pink[200], alignment: Alignment.bottomRight, child: Center( child: Text(_codeCB, softWrap: true, textAlign: TextAlign.center, style: const TextStyle(color: Colors.black, fontSize: 25)))), // ], ), ); }

navaronbracke commented 6 months ago

The MobileScanner() widget is shown, but it gets a layout size of zero. Did you start the controller?

You might need to provide the placeholder builder argument.

JP3871 commented 6 months ago

The MobileScanner() widget is shown, but it gets a layout size of zero. Did you start the controller?

You might need to provide the placeholder builder argument.

Hi Navaronbracke,

I have the area now, but when I created the apk: my area zone is not adjusted to 500x200 (width and height) but to the entire area. Buttons 'Pause' and 'scanner' have disappeared...

I test with new phone Nothing 2a (android v14) for your information

Could you give me an example of code, thanks

image

// Widget buildAreaScan(BuildContext context) { return Container( height: 200.0, width: 500.0, color: Colors.pink[200], alignment: Alignment.bottomRight, //child: ); }

      const SizedBox(height: 10),
      MobileScanner(
          controller: scanController,
          fit: BoxFit.contain,
          placeholderBuilder: (context, child) {
            return buildAreaScan(context);
          },
          scanWindow: Rect.fromCenter(
              center: MediaQuery.sizeOf(context).center(Offset.zero),
              width: 500,
              height: 200),
          onDetect: (BarcodeCapture barcodes) {
            setState(() {
              _codeCB = barcodes.toString();
            });
          }),
navaronbracke commented 6 months ago

We do have a sample app here https://github.com/juliansteenbakker/mobile_scanner/tree/master/example

It includes a scan window example as well.