搜尋套件、儲存庫與 APP 分類

套件詳情v4.9.0

barcode_scan2

一個用於透過攝像頭掃描二維條碼和QR碼的Flutter外掛。

AndroidiOS
近 30 天下載
2.1萬
喜歡數
307
Pub 分數
160

安裝套件

flutter pub add barcode_scan2

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

barcode_scan2 是一個 Flutter 插件,可使用設備的相機掃描二維條碼和 QR 碼。它為將條碼掃描功能整合到 Flutter 應用程式中提供簡單可靠的介面。此插件支援 Android 和 iOS 平台,適用於跨平台行動開發。透過最少的設定,開發者可快速為零售、物流、票務等應用新增掃描功能。原始碼公開於 GitHub,以確保透明度與客製化。

適用情境

  • 零售庫存管理
  • 活動票務掃描
  • 產品資訊查詢
  • 物流追蹤
  • 透過QR碼進行使用者驗證

主要特色

  • 即時條碼掃描
  • 支援二維條碼和QR碼
  • 跨平台相容性(Android 與 iOS)
  • 與 Flutter 的簡單整合
  • 開源且可自訂

適合對象

  • 需要條碼掃描的移動應用
  • 開發庫存或票務系統的開發者
  • 需要快速獲取二維碼數據的項目
  • 同時面向 Android 和 iOS 使用者的應用程式

使用建議

  • 兩個平台都需要相機權限
  • 可能需要額外的UI組件以獲得最佳使用者體驗
  • 性能取決於設備攝像頭的品質

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

GitHub license GitHub stars Pub GitHub forks

Reborned🎉

Original barcode_scan was discontinued, so barcode_scan2 was borned with sound null safety support🎉

barcode_scan2

A flutter plugin for scanning 2D barcodes and QR codes.

This provides a simple wrapper for two commonly used iOS and Android libraries:

  • iOS: https://github.com/mikebuss/MTBBarcodeScanner
  • Android: https://github.com/dm77/barcodescanner
Features
  • [x] Scan 2D barcodes
  • [x] Scan QR codes
  • [x] Control the flash while scanning
  • [x] Permission handling

Getting Started

Android

For Android, you must do the following before you can use the plugin:

  • Add the camera permission to your AndroidManifest.xml

    <uses-permission android:name="android.permission.CAMERA" />

  • This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See installing the Kotlin plugin.

Edit your project-level build.gradle file to look like this:

buildscript {
    ext.kotlin_version = '1.3.61'
    // ...
    dependencies {
        // ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
// ...

Edit your app-level build.gradle file to look like this:

apply plugin: 'kotlin-android'
// ...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // ...
}

Now you can depend on the barcode_scan plugin in your pubspec.yaml file:

dependencies:
    # ...
    barcode_scan2: any

Click "Packages get" in Android Studio or run flutter packages get in your project folder.

iOS

To use on iOS, you must add the the camera usage description to your Info.plist

<dict>
    <!-- ... -->
    <key>NSCameraUsageDescription</key>
    <string>Camera permission is required for barcode scanning.</string>
    <!-- ... -->
</dict>
iOS 26+ Compatibility

This fork includes a fix for the 10-15 second delay when dismissing the scanner on iOS 26+. The fix is built-in - no additional configuration required.

Usage

import 'package:barcode_scan2/barcode_scan2.dart';

void main() async {
  var result = await BarcodeScanner.scan();

  print(result.type); // The result type (barcode, cancelled, failed)
  print(result.rawContent); // The barcode content
  print(result.format); // The barcode format (as enum)
  print(result.formatNote); // If a unknown format was scanned this field contains a note
}

Advanced usage

You can pass options to the scan method:

import 'package:barcode_scan2/barcode_scan2.dart';

void main() async {

  var options = ScanOptions(
    // set the options
  );

  var result = await BarcodeScanner.scan(options: options);

  // ...
}
Supported options
Option Type Description Supported by
strings.cancel String The cancel button text on iOS iOS only
strings.flash_on String The flash on button text iOS + Android
strings.flash_off String The flash off button text iOS + Android
restrictFormat BarcodeFormat[] Restrict the formats which are recognized iOS + Android
useCamera int The index of the camera which is used for scanning (See BarcodeScanner.numberOfCameras) iOS + Android
autoEnableFlash bool Enable the flash when start scanning iOS + Android
android.aspectTolerance double Enable auto focus on Android Android only
android.useAutoFocus bool Set aspect ratio tolerance level used in calculating the optimal Camera preview size Android only
android.appBarTitle String Sets the text of the app bar Android only

Development setup

Setup protobuf

Mac:

$ brew install protobuf
$ brew install swift-protobuf

Windows / Linux: https://github.com/protocolbuffers/protobuf#protocol-compiler-installation

Activate the protobuf dart plugin:

$ flutter pub global activate protoc_plugin

Install theProtobuf Support plugin for IDEA / Android Studio or vscode-proto3 for VS Code

If you changed the protos.proto you've to execute the ./generate_proto.sh to update the dart / swift sources

Common problems

Android "Could not find org.jetbrains.kotlin:kotlin-stdlib-jre..."

Change org.jetbrains.kotlin:kotlin-stdlib-jre to org.jetbrains.kotlin:kotlin-stdlib-jdk (StackOverflow)

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案