flutterflutter-qrcode

Flutter QR Camera is not working when page is changed


i have a screen that scans qr code and sends some informations to my db, when i navigate to camera page first time camera works perfectly but when i navigate to another page then back to camera page again camera is not working

if i save codes, camera works again. i think its about state but i cannot manage to solve this problem.

void initState() {
    super.initState();
    _animationController =
        AnimationController(vsync: this, duration: const Duration(seconds: 1));

    _animation = Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
        parent: _animationController, curve: Curves.easeInOutCirc));

    _animationController.forward();
  }

  void dispose() {
    try {
      qrViewController?.dispose();
    } catch (e) {
      print("error");
    }
    super.dispose();
  }

Future<void> reassemble() async {
    // TODO: implement reassemble
    super.reassemble();

    if (Platform.isAndroid) {
      await qrViewController!.pauseCamera();
    }
    qrViewController!.resumeCamera();
  }


void onQrViewCreated(QRViewController qrViewController) {
setState(() {
    this.qrViewController = qrViewController;
    });
    qrViewController.scannedDataStream.listen((event) async {}
}
    


Solution

  • I changed my qr_code_scanner package with same publisher's mobile_scanner and this is working well