【问题标题】:Scan barcode in Android emulator using virtual scene使用虚拟场景在 Android 模拟器中扫描条码
【发布时间】:2019-06-30 03:12:29
【问题描述】:

我正在使用 flutter_barcode_reader 插件开发一个 Flutter 项目。在物理 Android 设备上一切正常,但是当我尝试扫描相机中的二维码 virtual scene 时,无法让二维码扫描仪在模拟器上做出反应。

有没有什么方法可以在不使用网络摄像头或物理设备的情况下实现这一点?

【问题讨论】:

标签: android flutter android-emulator qr-code barcode-scanner


【解决方案1】:

flutter_barcode_reader 插件似乎不再可用。

由于还有许多其他库提供了更多更好的 条码扫描功能,我决定停止 这个项目的开发。

为了专注于您关于使用模拟器扫描二维码的问题,我已经设法从虚拟场景中扫描二维码。

这是我用来模拟的sample app

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/services.dart';

void main() => runApp(MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    ));

class HomePage extends StatefulWidget {
  @override
  HomePageState createState() {
    return new HomePageState();
  }
}

class HomePageState extends State<HomePage> {
  String result = "Hey there !";

  Future _scanQR() async {
    try {
      String qrResult = await BarcodeScanner.scan();
      setState(() {
        result = qrResult;
      });
    } on PlatformException catch (ex) {
      if (ex.code == BarcodeScanner.CameraAccessDenied) {
        setState(() {
          result = "Camera permission was denied";
        });
      } else {
        setState(() {
          result = "Unknown Error $ex";
        });
      }
    } on FormatException {
      setState(() {
        result = "You pressed the back button before scanning anything";
      });
    } catch (ex) {
      setState(() {
        result = "Unknown Error $ex";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("QR Scanner"),
      ),
      body: Center(
        child: Text(
          result,
          style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),
        ),
      ),
      floatingActionButton: FloatingActionButton.extended(
        icon: Icon(Icons.camera_alt),
        label: Text("Scan"),
        onPressed: _scanQR,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    );
  }
}

由于您没有提供示例,我无法确定问题出在插件还是实现上。或许你可以试试pub.dev中提供的其他插件:

【讨论】:

    猜你喜欢
    • 2014-01-11
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多