首页 > 解决方案 > 用相机包拍照并检查条形码阅读器

问题描述

**首先我为这个大代码道歉。我的 Flutter 应用程序使用相机pugin 和条形码阅读器使用google_ml_kit插件来拍摄和扫描 nid。从这里拍照帮助当我拍照并尝试读取条形码时它不起作用,但相同的代码由image_picker包工作,但我想用相机包做任何帮助将是 appriciate **

给我这个错误

 W/(19978): Unable to open '/system/framework/qcom.fmradio.jar': No such 
 file or directory
 W/art     (19978): Failed to open zip 
 archive'/system/framework/qcom.fmradio.jar': I/O Error 
     W/DynamiteModule(19978): Local module descriptor class for 
   com.google.firebase.ml.vision.dynamite.barcode not found.
   W/DynamiteModule(19978): Local module descriptor class for 
    com.google.android.gms.vision.dynamite.barcode not found.
   I/DynamiteModule(19978): Considering local module 
  com.google.android.gms.vision.dynamite.barcode:0 and remote module 
  com.google.android.gms.vision.dynamite.barcode:0
   I/DynamiteModule(19978): Considering local module 
  com.google.android.gms.vision.barcode:0 and remote module 
  com.google.android.gms.vision.barcode:1
  I/DynamiteModule(19978): Selected remote version of 
  com.google.android.gms.vision.barcode, version >= 1
 V/DynamiteModule(19978): Dynamite loader version >= 2, using 
 loadModule2NoCrashUtils
 W/ResourceType(19978): ResTable_typeSpec entry count inconsistent: given 67, 
 previously 69
  D/ResourcesManager(19978): For user 0 new overlays fetched Null
  W/System  (19978): ClassLoader referenced unknown path: 
  /data/data/com.google.android.gms/app_chimera/m/00000009/n/armeabi
  D/ResourcesManager(19978): For user 0 new overlays fetched Null

启动相机并拍照以读取条形码

    class _EKycCustomerNidBackSideState extends State<EKycCustomerNidBackSide> {
     String imagePath;
     CameraController _controller;
    Future<void> _initializeControllerFuture;
    var barcodeString;
     BarcodeScanner barcodeScanner;
      List<Barcode> barcodes;

     @override
      void initState() {
      super.initState();
      _controller = CameraController(
      widget.camera,
      ResolutionPreset.high,
      );
     _initializeControllerFuture = _controller.initialize();
    }
   @override
   void dispose() {
    _controller?.dispose();
   super.dispose();
    }

    errorDialog(String title, String msg) {
     showDialog(
     context: context,
    builder: (_) => AlertDialog(
    title: Text(
      title,
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
    content: Text(
      msg,
      textAlign: TextAlign.center,
    ),
    actions: [
      TextButton(
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => DisplayPictureScreen(
                nameString: widget.customerid,
              ),
            ),
          );
        },
        child: Text('SKIP'),
      ),
      TextButton(
        onPressed: () => Navigator.pop(context),
        child: Text('TRY AGAIN'),
      ),
      ],
      ),
     );
     }

      Future decode() async {
      await _initializeControllerFuture;
       await _controller.lockCaptureOrientation();
       var barcodeString = '';
       var image = await _controller.takePicture();
       final inputImage = InputImage.fromFilePath(image.path);
        barcodeScanner = GoogleMlKit.vision.barcodeScanner();
        final result = await barcodeScanner.processImage(inputImage);
         setState(() {
         imagePath = image.path;
         barcodes = result;
         });
         barcodeString = barcodes[0].barcodeUnknown.rawValue;
         if (barcodeString.replaceAll(' ', '').contains("6427886723")) {
         print('nid match');
         Navigator.push(
         context,
          MaterialPageRoute(
          builder: (context) => DisplayPictureScreen(
            barcode: barcodeString,
           ),
          ),
         );
        } else {
       print('nid not match');
      }
     }

     @override
     Widget build(BuildContext context) {
      return Scaffold(
      appBar: AppBar(
       title: Text('NID BackSide Image Capture'),
       actions: [
        IconButton(
         icon: Icon(Icons.more_vert),
        onPressed: () {},
       )
       ],
      ),
       body: FutureBuilder<void>(
       future: _initializeControllerFuture,
       builder: (context, snapshot) {
       if (snapshot.connectionState == ConnectionState.done) {
        return Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: AspectRatio(
            aspectRatio: _controller.value.aspectRatio,
            child: Stack(
              fit: StackFit.expand,
              children: <Widget>[
                CameraPreview(_controller),
                Positioned(
                  left: MediaQuery.of(context).size.width * 0.3,
                  top: MediaQuery.of(context).size.height * 0.1,
                  child: Text('NID Back Image Capture'),
                ),
                Positioned(
                  top: MediaQuery.of(context).size.height * 0.20,
                  left: 10,
                  right: 10,
                  bottom: MediaQuery.of(context).size.height * 0.35,
                  child: Container(
                    height: MediaQuery.of(context).size.height * 0.35,
                    width: MediaQuery.of(context).size.width * 0.9,
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.red, width: 1.5),
                      borderRadius: BorderRadius.circular(12.0),
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    width: double.infinity,
                    height: 140.0,
                    padding: EdgeInsets.all(20.0),
                    color: Colors.grey,
                    child: Stack(
                      children: <Widget>[
                        Align(
                          alignment: Alignment.center,
                          child: Material(
                            color: Colors.transparent,
                            child: InkWell(
                              borderRadius:
                              BorderRadius.all(Radius.circular(50.0)),
                              onTap: () async {
                                await decode();
                              },
                              child: Column(
                                children: [
                                  Text(
                                    'Put your Nid inside the frame and take a picture',
                                    style: TextStyle(
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Container(
                                    padding: EdgeInsets.all(4.0),
                                    child: Image.asset(
                                      'assets/images/shutter_1.png',
                                      width: 72.0,
                                      height: 72.0,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
       } else {

          return Center(
          child: CircularProgressIndicator(),
          );
         }
        },
       ),
      );
     }
    }

标签: flutterdartbarcode

解决方案


推荐阅读