Qr扫描仪未显示结果

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

我正在尝试使用条形码扫描依赖在我的项目中实现QR扫描仪。当我在其他项目中运行代码时,效果很好,但是当我在项目中使用完全相同的代码时,则没有扫描结果。我正在我的项目中使用提供程序体系结构,但是我使此页面独立于提供程序。

    import 'dart:async';
    import 'dart:io' show Platform;

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

   // void main() {
  //   runApp(AttendeeQrscanner());
   // }

   class AttendeeQrscanner extends StatefulWidget {
   @override
   AttendeeQrscannerState createState() => AttendeeQrscannerState();
   }

  class AttendeeQrscannerState extends State<AttendeeQrscanner> {
  ScanResult scanResult;



 var _aspectTolerance = 0.00;
 var _selectedCamera = -1;
 var _useAutoFocus = true;
 var _autoEnableFlash = false;

 static final _possibleFormats = BarcodeFormat.values.toList()
..removeWhere((e) => e == BarcodeFormat.unknown);

 List<BarcodeFormat> selectedFormats = [..._possibleFormats];


 @override
 Widget build(BuildContext context) {
 var contentList = <Widget>[
  if (scanResult != null)
    Card(
      child: Column(
        children: <Widget>[
          ListTile(
            title: Text("Result Type"),
            subtitle: Text(scanResult.type?.toString() ?? ""),
          ),
          ListTile(
            title: Text("Raw Content"),
            subtitle: Text(scanResult.rawContent ?? ""),
          ),
          ListTile(
            title: Text("Format"),
            subtitle: Text(scanResult.format?.toString() ?? ""),
          ),
          ListTile(
            title: Text("Format note"),
            subtitle: Text(scanResult.formatNote ?? ""),
          ),
        ],
      ),
    ),



   ];
   return MaterialApp(
   debugShowCheckedModeBanner: false,
   home: Scaffold(
    appBar: AppBar(
      title: Text('Barcode Scanner Example'),
      actions: <Widget>[
        IconButton(
          icon: Icon(Icons.camera),
          tooltip: "Scan",
          onPressed: scan,
        )
      ],
    ),
    body: ListView(
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      children: contentList,
    ),
   ),
  );
 }

Future scan() async {
try {
  var options = ScanOptions(

    restrictFormat: selectedFormats,
    useCamera: _selectedCamera,
    autoEnableFlash: _autoEnableFlash,
    android: AndroidOptions(
      aspectTolerance: _aspectTolerance,
      useAutoFocus: _useAutoFocus,
    ),
  );

  var result = await BarcodeScanner.scan(options: options);
 print("scan resulllt $result");
  setState(() => scanResult = result);
 } on PlatformException catch (e) {
  var result = ScanResult(
    type: ResultType.Error,
    format: BarcodeFormat.unknown,
  );

  if (e.code == BarcodeScanner.cameraAccessDenied) {
    setState(() {
      result.rawContent = 'The user did not grant the camera permission!';
    });
   } else {
    result.rawContent = 'Unknown error: $e';
   }
  setState(() {
    scanResult = result;
  });
  }
 }
}

我的调试控制台显示的内容

D / mali_winsys(6082):EGLint new_window_surface(egl_winsys_display *,void *,EGLSurface,EGLConfig,egl_winsys_surface **,EGLBoolean)返回0x3000D / SurfaceView(6082):surfaceChanged(1080,2214)1#8 io.flutter.view.FlutterView {32a2498 VFE ...... ........ 0,0-1080,2214}D / ViewRootImpl @ 49ab5fMainActivity:MSG_WINDOW_FOCUS_CHANGED 1 1D / InputMethodManager(6082):prepareNavigationBarInfo()DecorView @ 6f74f31 [MainActivity]D / InputMethodManager(6082):getNavigationBarColor()-855310D / InputMethodManager(6082):prepareNavigationBarInfo()DecorView @ 6f74f31 [MainActivity]D / InputMethodManager(6082):getNavigationBarColor()-855310V / InputMethodManager(6082):开始输入:tba = com.event.eventusAiV3 ic = null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true,NavVisible:true,NavTrans:falseD / InputMethodManager(6082):startInputInner-ID:0I / InputMethodManager(6082):startInputInner-mService.startInputOrWindowGainedFocusD / InputTransport(6082):构建的输入通道:fd = 106D / InputTransport(6082):输入通道损坏:fd = 111D / SurfaceView(6082):onWindowVisibilityChanged(8)false me.dm7.barcodescanner.core.CameraPreview {d627f45 VE ............. 0,0-1116,1984} of ViewRootImpl @ ab30553 [ BarcodeScannerActivity]D / SurfaceView(6082):show()Surface(name = SurfaceView-com.event.eventusAiV3 / de.mintware.barcode_scan.BarcodeScannerActivity @ d627f45 @ 0 [6082])/ @ 0xa15669a me.dm7.barcodescanner.core.CameraPreview { d627f45 VE ..... ........ 0,0-1116,1984}D / SurfaceView(6082):surfaceDestroyed callback.size 0#2 me.dm7.barcodescanner.core.CameraPreview {d627f45 V.E ...... ........ 0,0-1116,1984}D / SurfaceView(6082):destroy()Surface(name = SurfaceView-com.event.eventusAiV3 / de.mintware.barcode_scan.BarcodeScannerActivity @ d627f45 @ 0 [6082])/ @ 0xa15669a me.dm7.barcodescanner.core.CameraPreview { d627f45 VE ..... ........ 0,0-1116,1984}W / libEGL(6082):EGLNativeWindowType 0x79354bd010断开连接失败D / OpenGLRenderer(6082):eglDestroySurface = 0x7963f22180,0x79354bd000D / ViewRootImpl @ ab30553BarcodeScannerActivity:中继返回:旧= [0,0] [1080,2340]新= [0,0] [1080,2340]结果= 0x5表面= {假0}已更改= trueD / ViewRootImpl @ ab30553BarcodeScannerActivity:已停止(true)old = falseD / SurfaceView(6082):windowStopped(true)false me.dm7.barcodescanner.core.CameraPreview {d627f45 VE ............. 0,0-1116,1984} of ViewRootImpl @ ab30553 [ BarcodeScannerActivity]D / ViewRootImpl @ ab30553BarcodeScannerActivity:dispatchDetachedFromWindowD / InputTransport(6082):输入通道被破坏:fd = 104

android ios flutter qr-code barcode-scanner
1个回答
0
投票

我刚使用了fast_qr_reader_view插件,而不是条形码_scan。我现在正在牵引自己的皮带,但我认为我的回答可能会有所帮助。

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