页面更改时Flutter二维码相机不工作



我有一个屏幕,它扫描qr码并向我的数据库发送一些信息,当我第一次导航到相机页面时,相机工作正常,但当我导航到另一个页面,然后再次返回相机页面时相机不工作

如果我保存代码,相机会再次工作。我认为这与国家有关,但我无法解决这个问题。

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 {}
}

我用同一发行商的mobile_scanner更改了我的qr_code_scanner包,运行良好

最新更新