搜索分类、插件与代码仓

插件详情v0.14.0

qr_code_dart_scan

一个使用 Dart 解码器在 iOS 和 Android 上均能正常工作的二维码扫描器。

AndroidiOS
近 30 天下载
1.4万
喜欢数
67
Pub 分数
120

安装插件

flutter pub add qr_code_dart_scan

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个适用于 Flutter 应用的跨平台二维码扫描器,利用基于 Dart 的解码器在 Android 和 iOS 上无缝工作。它无需依赖原生相机 API 即可实现实时扫描,为在 Dart 中直接集成二维码功能提供轻量且高效的解决方案。该包非常适合需要从二维码快速提取数据的应用场景,例如票务、身份验证或产品信息检索。设计简洁,易于集成,解码性能可靠。

适合场景

  • 在移动应用中扫描二维码
  • 数字票务验证
  • 产品信息查询
  • 通过二维码进行用户身份验证
  • 设备间快速数据传输

主要特点

  • 跨平台支持(iOS 和 Android)
  • Dart 原生解码引擎
  • 轻便且快速
  • 简单 API 集成
  • 实时扫描功能

适合对象

  • 开发需要二维码扫描功能的移动应用的开发者
  • 需要离线二维码解码的应用
  • 项目避免原生相机依赖

使用建议

  • 仅限二维码(不包括条形码)
  • 性能取决于设备摄像头的质量
  • 可能需要相机权限
  • 无内置UI——需要自定义实现

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

pub package

QRCodeDartScan

A QR code scanner that works on both iOS and Android using dart decoder.

Scanning normal Qr code Scanning invert Qr code

APK DEMO

Features

  • Camera scan preview in a widget
  • Scan QRCode
  • Scan inverted QRCode

Supported platforms

This package is limited per camera pluggin support.

Platform Scan live Scan take picture
Android :white_check_mark: :white_check_mark:
IOS :white_check_mark: :white_check_mark:
WEB :white_check_mark:
Windows
MacOS
Linux

Supported Formats

  • QR_CODE
  • AZTEC
  • DATA_MATRIX
  • PDF_417
  • CODE_39
  • CODE_93
  • CODE_128
  • EAN_8
  • EAN_13
  • ITF

Installation

First, add qr_code_dart_scan as a dependency in your pubspec.yaml file.

iOS

iOS 10.0 of higher is needed to use the camera plugin. If compiling for any version lower than 10.0 make sure to check the iOS version before using the camera plugin. For example, using the device_info plugin.

Add two rows to the ios/Runner/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.
  • and one with the key Privacy - Microphone Usage Description and a usage description.

Or in text format add the key:

<key>NSCameraUsageDescription</key>
<string>Can I use the camera please?</string>
<key>NSMicrophoneUsageDescription</key>
<string>Can I use the mic please?</string>
Android

Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

It's important to note that the MediaRecorder class is not working properly on emulators, as stated in the documentation: https://developer.android.com/reference/android/media/MediaRecorder. Specifically, when recording a video with sound enabled and trying to play it back, the duration won't be correct and you will only see the first frame.

dependency_overrides:
  camera_android_camerax: 0.6.14
Using

    return Scaffold(
      body: QRCodeDartScanView(
        onCameraError: (String error) {
          debugPrint('Error: $error');
        },
        // cropRect: CropRect(left: 0, top: 0, width: 100, height: 100), // You can crop the image to improve accuracy by specifying a rectangle region. ( default = null)
        // imageDecodeOrientation: ImageDecodeOrientation.original, // you can force how the image orientation will be decoded (default = original)
        typeScan: TypeScan.live, // if TypeScan.takePicture will try decode when click to take a picture(default TypeScan.live)
        // intervalScan: const Duration(seconds:1)
        // onResultInterceptor: (old,new){
        //  do any rule to controll onCapture.
        // }
        // takePictureButtonBuilder: (context,controller,isLoading){ // if typeScan == TypeScan.takePicture you can customize the button.
        //    if(loading) return CircularProgressIndicator();
        //    return ElevatedButton(
        //       onPressed:controller.takePictureAndDecode,
        //       child:Text('Take a picture'),
        //    );
        // }
        // resolutionPreset: = QrCodeDartScanResolutionPreset.high,
        // formats: [ // You can restrict specific formats.
        //  BarcodeFormat.qrCode,
        //  BarcodeFormat.aztec,
        //  BarcodeFormat.dataMatrix,
        //  BarcodeFormat.pdf417,
        //  BarcodeFormat.code39,
        //  BarcodeFormat.code93,
        //  BarcodeFormat.code128,
        //  BarcodeFormat.ean8,
        //  BarcodeFormat.ean13,
        // ],
        // croppingStrategy: CroppingStrategy.cropCenterSquare(
        //   squareSizeFactor: 0.7,
        // ),
        onCapture: (ScanResult result) {
          // do anything with result
          // result.text      -> String
          // result.format    -> BarcodeFormat
          // result.corners   -> List<Point<double>>, in camera preview
          //                     coordinates. Use `result.corners.toOffsets`
          //                     to paint them.
          // result.rawBytes  -> Uint8List?
          // result.timestamp -> DateTime
        },
      ),
    );
    

ATTENTION

Always use this package in portrait mode.

There is a bug in the camera plugin that sometimes the image is rotated 90 degrees, to avoid this problem, you can use the imageDecodeOrientation parameter to force the image to be decoded in the correct orientation.

For example, if you are reading an ITF code, you can force the image to be decoded in landscape orientation.

imageDecodeOrientation: ImageDecodeOrientation.landscape,

if you want to force the image to be decoded in portrait orientation, you can use the following code:

imageDecodeOrientation: ImageDecodeOrientation.portrait,
Camera performance

The decoder process is done in dart code. So, in flutter debug mode, you will not have a good performance. But in release mode, the performance is very better.

所属分类

依赖

依赖清单 6 项

源码仓库

使用此插件的项目