简体   繁体   中英

Flutter qr_code_scanner camera doesn't open when i click a textfield inside of dialog

I using qr_code_scanner for scan a qr code & barcodes. Its scanning perfectly. But when i want to use dialog after scan for ask how much product did you scan and after that check it and control it.But when i use textfield inside of dialog and when i tap textfield camera stops working and its stays in black screen. What should i do? What is wrong? My codes for scan:

void _onQRViewCreated(QRViewController controller) {
      this.controller = controller; 
      controller.scannedDataStream.listen((scanData) { 
        controller.pauseCamera();
        player.play("scanner_sound.mp3");
        inspect(args);
        if (args.Barcode == scanData.code) {
          showDialog(
              context: context,
              builder: (context) {
                return WillPopScope(
                  onWillPop: () async {
                    Navigator.pop(context);
                    controller.resumeCamera();
                    return true;
                  },
                  child: AlertDialog(
                    title: const Text('Ürün Giriş'),
                    content: Column(
                      children: [
                        const Text('Bu üründen kaç adet okutuldu ?'),
                        TextField(
                          keyboardType: TextInputType.number,
                          controller: _controller,
                        ),
                      ],
                    ),
                    actions: <Widget>[
                      TextButton(
                          onPressed: () { 
                            bool isTrue = checkScannedCount(int.parse(_controller.text));
                            if (isTrue) {
                              var model = args.copyWith(ScannedCount: args.Count);
                              context.read<ProductCubit>().updateProduct(model);
                              Navigator.pop(context);
                              Navigator.pop(context);
                            } else {
                              ScaffoldMessenger.of(context).showSnackBar(
                                const SnackBar(
                                  content: Text("Lütfen sayımı tekrarlayınız."),
                                ),
                              );

                              Navigator.pop(context);
                              controller.resumeCamera(); //Its not starting camera again.
                            }
                          },
                          child: const Text('Tamam')),
                    ],
                  ),
                );
              });
        } else {
          showDialog(
              context: context,
              builder: (context) {
                return WillPopScope(
                  onWillPop: () async {
                    Navigator.pop(context);
                    controller.resumeCamera();
                    return true;
                  },
                  child: AlertDialog(
                    title: const Text('Hatalı Barkod veya Ürün'),
                    content: const Text('Yanlış ürünü veya barkodu okutuyor olabilirsiniz. Kontrol edip tekrar ediniz.'),
                    actions: <Widget>[
                      TextButton(
                          onPressed: () {
                            Navigator.pop(context);
                            controller.resumeCamera();
                          },
                          child: const Text('Tamam')),
                    ],
                  ),
                );
              });
        }
      });
    }

qr_code_scanner no longer supported. Since the underlying frameworks of this package, zxing for android and MTBBarcodescanner for iOS are both not longer maintaned. use mobile_scanner

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