1

As Soon As I Click on The Camera Button The App Crashes.

It is not Asking For Any Permission Also.

I Have Included The Activity File in the Manifest Also

This is The Code I Am Using and The plugin I Am Using is barcode_scan:

Even After Searching a Lot I Am Unable To get to The Problem. Help Would Be Appreciated.

class _AuditPage extends State<AuditPage>{ String result = "Scan The Barcode!"; Future _scanQR() async{ try{ String qrCode = await BarcodeScanner.scan(); setState(() { result = qrCode; }); }on PlatformException catch (ex){ if(ex.code==BarcodeScanner.CameraAccessDenied){ setState(() { result="Camera Permission Was Denied"; }); }else{ setState(() { result="Unknown Error $ex!"; }); } } on FormatException { setState(() { result = "You Pressed The Back Button Before Scanning"; }); } catch (ex){ setState(() { result="Unknown Error $ex!"; }); } } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomPadding: false, appBar: AppBar( title: Text("Bhaifi"), ), drawer: DrawerPage(), body: Center( child:Text( result, ), ), floatingActionButton:FloatingActionButton.extended( icon: Icon(Icons.camera_alt), label: Text("Scan"), onPressed: _scanQR, ), floatingActionButtonLocation:FloatingActionButtonLocation.centerFloat, ); } } 
4
  • you want to take a look to AndroidX issue: I had a similar situation, you can grab some code from this post: stackoverflow.com/questions/55223002/… not the solution or the updates, but my troubleshooting in the original post; I hope it helps Commented Mar 25, 2019 at 8:28
  • Thanks But Not Working Commented Mar 25, 2019 at 9:25
  • try using the "old one": barcode_scan: ^0.0.8 , if doesn't work try without " ^ ": just "barcode_scan: 0.0.8" Commented Mar 25, 2019 at 9:30
  • do not specify the version of barcode_scan it will tack suitable version for you. Commented Mar 25, 2019 at 13:01

1 Answer 1

1

You're probably not adding the dependency in your AndroidManifest.xml folder, The same issue I had, Just modify scanQR() function.

Try this:

Future scanQR() async { try { String barcode; await BarcodeScanner.scan().then((onValue) { setState(() { barcode = onValue.toString(); }); }).catchError((onError) { print(onError); }); setState(() => this.barcode = barcode); } on PlatformException catch (e) { if (e.code == BarcodeScanner.CameraAccessDenied) { setState(() { this.barcode = 'camera permission not granted!'; }); } else { setState(() => this.barcode = 'Unknown error: $e'); } } on FormatException { setState(() => this.barcode = '(User returned)'); } catch (e) { setState(() => this.barcode = 'Unknown error: $e'); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.