【问题标题】:Implementing Google Vision API with Flutter使用 Flutter 实现 Google Vision API
【发布时间】:2018-06-27 18:19:45
【问题描述】:

我不确定如何将其整合到现有的颤振项目中,并且我无法在网上找到任何有用的指南或提示。我希望实现仅二维条码扫描仪,而现有的颤振条码扫描仪都没有该选项。

我知道 ZXing 也有 2d 唯一的功能,所以如果有人能指出如何在颤振中实现它们的方向,我可以动摇使用它

【问题讨论】:

    标签: flutter barcode zxing google-vision


    【解决方案1】:

    请检查此网址

    https://pub.dartlang.org/packages/qrcode_reader 这是实现代码

    import 'dart:async';
    
    import 'package:flutter/material.dart';
    import 'package:qrcode_reader/QRCodeReader.dart';
    
    void main() {
      runApp(new MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: 'QRCode Reader Demo',
          home: new MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      final Map<String, dynamic> pluginParameters = {
      };
    
      @override
      _MyHomePageState createState() => new _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      Future<String> _barcodeString;
    
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: const Text('QRCode Reader Example'),
          ),
          body: new Center(
              child: new FutureBuilder<String>(
                  future: _barcodeString,
                  builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
                    return new Text(snapshot.data != null ? snapshot.data : '');
                  })),
          floatingActionButton: new FloatingActionButton(
            onPressed: () {
              setState(() {
                _barcodeString = new QRCodeReader()
                    .setAutoFocusIntervalInMs(200)
                    .setForceAutoFocus(true)
                    .setTorchEnabled(true)
                    .setHandlePermissions(true)
                    .setExecuteAfterPermissionGranted(true)
                    .scan();
              });
            },
            tooltip: 'Reader the QRCode',
            child: new Icon(Icons.add_a_photo),
          ),
        );
      }
    }
    

    【讨论】:

    • 当我尝试实现它时,您的示例会引发错误:E/flutter (4428): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] 未处理的异常:E/颤振(4428):MissingPluginException(在通道 qrcode_reader 上找不到方法 readQRCode 的实现)E/flutter(4428):#0 MethodChannel.invokeMethod(包:flutter/src/services/platform_channel.dart:278:7)E/flutter( 4428): E/flutter (4428): #1 QRCodeReader.scan (package:qrcode_reader/QRCodeReader.dart:67:27) E/flutter (4428):
    【解决方案2】:

    这可以通过使用flutter barcode_scan依赖来完成。

    Future _openQRScanner() async {
    try {
      // Below code will open camera preview and return result after qr scan 
      String _content = await BarcodeScanner.scan();
      setState(() => this._content = _content);
    } on PlatformException catch (e) {
      if (e.code == BarcodeScanner.CameraAccessDenied) {
        showSnackBar('Please grant camera permission!');
        setState(() {
          this._content = null;
        });
      } else {
        showSnackBar('Error: $e');
        setState(() {
          this._content = null;
        });
      }
    } on FormatException {
      showSnackBar('User pressed "back" button before scanning');
      setState(() {
        this._content = null;
      });
    } catch (e) {
      showSnackBar('Error: $e');
      setState(() {
        this._content = null;
      });
    }
    }
    

    请查找repo

    如果您想了解 Flutter,您可以在我们的 companie’s Github 页面找到一些很好的示例。另外,您可以查看我们公司的页面FlutterDevs

    【讨论】:

      猜你喜欢
      • 2019-05-11
      • 2021-03-01
      • 2020-10-22
      • 2021-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多