简体   繁体   中英

Flutter App crashes emulator when opening camera

I am trying to build a bar code scanner app in Flutter. For this, I am using this plugin. I added it to pubspec.yaml , modified the AndroidMainfest.xml file and added the simple code as below:

Future _scanQR() async {
    try {
      var qrResult = await BarcodeScanner.scan();
      result = qrResult as String;
    } catch (ex) {
//      result = "Unknown Error $ex";
    }
  }

The above method is invoked on a button press. So the app loads and I click the button, the whole emulator crashes without any logs or error message. Here is the whole logcat I recorded during the flow. In the end, it says

2020-04-19 20:20:21.285 1740-2027/? I/Camera2ClientBase: Camera 0: Opened. Client: io.yeshwanthvshenoy.addup (PID 4260, UID 10086)

Here is another log from the default camera app. I can't seem to find out why this is happening. My emulator settings are all default, I didn't change any setting except the back camera one which is set to Webcam0 . The possible options where virtual scene , none , emulated and webcam0 . Is it maybe that my Mac is not giving permissions to AVD to access camera? How can I check that if so??

Simulators don't have camera, so you need to avoid executing your code on simulators. Using the device info plugin you can get various information about the device you're running on, including isPhysicalDevice for both android and iOS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM