Search code examples
androidflutterdartcameraqr-code

Flutter using QRView but the camera doesn't open until I tap the container


I'm using QRView but the camera doesn't open until I tap/click the container. I want the camera to open while the page is rendered. How can i fix that?

Here is my code:

              Container(
            height: ScreenSize.getScreenWidth(context) / 1.6,
            width: ScreenSize.getScreenWidth(context) / 1.6,
            color: Colors.pink,
            child: QRView(
              key: qrKey,
              onQRViewCreated: _onQRViewCreated,

            ),
          ),

Here is _onQRViewCreated function:

  void _onQRViewCreated(QRViewController controller) {
     this.controller = controller;
     controller.scannedDataStream.listen((scanData) {
     setState(() {
      result = scanData;
     });
   });
  }

Solution

  • I found it just add this line

    controller.resumeCamera();

    Function is:

      void _onQRViewCreated(QRViewController controller) {
         this.controller = controller;
         controller.resumeCamera();
         controller.scannedDataStream.listen((scanData) {
         setState(() {
          result = scanData;
         });
       });
      }