使用 Flutter 实现 Google Vision API

问题描述 投票:0回答:3

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

我知道 ZXing 也只有 2d 功能,所以如果有人能指出如何在 flutter 中实现它们的方向,我可能会倾向于使用它

flutter barcode zxing google-vision
3个回答
0
投票

请检查此网址

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),
      ),
    );
  }
}

0
投票

这可以通过使用 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;
  });
}
}

enter image description here

enter image description here

请找到repo

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


0
投票

qrcode_reader - Dart 3 不兼容

© www.soinside.com 2019 - 2024. All rights reserved.