繁体   English   中英

Qr 扫描仪不显示结果

[英]Qr scanner not showing result

我正在尝试使用barcode_scan 依赖项在我的项目中实现QR 扫描仪。 当我在不同的项目中运行代码时,它工作正常,但是当我在项目中使用完全相同的代码时,它没有显示扫描结果。 我在我的项目中使用 Provider 架构,但我正在使这个页面独立于 Provider。

    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) returns 0x3000 D/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 1 D/InputMethodManager(6082): prepareNavigationBarInfo() DecorView@6f74f31[MainActivity ] D/InputMethodManager(6082): getNavigationBarColor() -855310 D/InputMethodManager(6082): prepareNavigationBarInfo() DecorView@6f74f31[MainActivity] D/InputMethodManager(6082): getNavigationBarColor() -855310 V/InputMethodManager(6082): 开始输入: tba=com.event.eventusAiV3 ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true, NavVisible: true, NavTrans: false D/InputMethodManager(6082): startInputInner - Id: 0 I/InputMethodManager(6082): startInputInner - mService.startInputOrWindowGainedFocu s D/InputTransport(6082):输入通道构造:fd=106 D/InputTransport(6082):输入通道被破坏:fd=111 D/SurfaceView(6082):onWindowVisibilityChanged(8) false me.dm7.barcodescanner.core.CameraPreview {d627f45 VE..... ........ ViewRootImpl@ab30553[BarcodeScannerActivity] 的 0,0-1116,1984} 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 VE..... ........ 0,0-1116,1984 } D/SurfaceView(6082):销毁()表面(名称=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): EGLN ativeWindowType 0x79354bd010 断开连接失败 D/OpenGLRenderer(6082): eglDestroySurface = 0x7963f22180, 0x79354bd000 D/ViewRootImpl@ab30553BarcodeScannerActivity: Relayout 返回: old=[0,0][1080,2340] new=[0,0][1080,3] 结果=0x5 表面={假 0} 更改=真 D/ViewRootImpl@ab30553BarcodeScannerActivity:停止(真)旧 =假 D/SurfaceView(6082):windowStopped(真)假 me.dm7.barcodescanner.core.CameraPreview{d627f45 VE.. ... ........ ViewRootImpl@ab30553[BarcodeScannerActivity] 的 0,0-1116,1984} D/ViewRootImpl@ab30553BarcodeScannerActivity:dispatchDetachedFromWindow D/InputTransport(6082):输入通道被破坏:fd=104

我只是使用 fast_qr_reader_view 插件而不是barcode_scan。 此时我正在拉自己的皮带,但我认为我的回答可以帮助其他人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM