[英]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.