Amr Ahmed
Amr Ahmed

Reputation: 203

Flutter - How to scan QR code with front camera?

i want to be able to scan QR code in my app with the front camera but all the available plugins supports only the main camera and dont have any option to capture from front cam, is there is any solution to this problem in the mainwhile?

Upvotes: 3

Views: 2652

Answers (1)

Manuel Abud
Manuel Abud

Reputation: 26

You can configure it in the options of the scan function:

Future scan() async {
    print("Scanning!!!");
    try {
      String barcode = await BarcodeScanner.scan(
        options: ScanOptions(
          useCamera: 1,
        )
      ).then((value) { return value.rawContent;});
      setState(() => this.barcode = barcode);
    }  catch (e) {
      if (e.code == BarcodeScanner.cameraAccessDenied) {
        setState(() {
          this.barcode = 'The user did not grant the camera permission!';
        });
      } else {
        setState(() => this.barcode = 'Unknown error: $e');
      }
    } 
  }

Using the number 1 in the useCamera property in ScanOptions means the front camera.

Hope it helps.

Upvotes: 1

Related Questions