barcode_scan2는 디바이스의 카메라를 사용하여 2차원 바코드와 QR 코드를 스캔할 수 있는 Flutter 플러그인입니다. 이 플러그인은 Flutter 애플리케이션에 바코드 스캔 기능을 통합하기 위한 간단하고 신뢰할 수 있는 인터페이스를 제공합니다. Android 및 iOS 플랫폼을 모두 지원하므로 크로스플랫폼 모바일 개발에 적합합니다. 최소한의 설정으로 소매, 물류, 티켓팅 등 다양한 분야에서 사용되는 앱에 스캔 기능을 빠르게 추가할 수 있습니다. 소스 코드는 GitHub에서 공개되어 있어 투명성과 맞춤형 수정이 가능합니다.
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';
voidmain() async {
var result = awaitBarcodeScanner.scan();
print(result.type); // The result type (barcode, cancelled, failed)print(result.rawContent); // The barcode contentprint(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';
voidmain() async {
var options = ScanOptions(
// set the options
);
var result = awaitBarcodeScanner.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