2017-10-30 01:05:11 +08:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
2020-02-20 06:36:18 +08:00
|
|
|
/// Barcode scanner plugin
|
|
|
|
/// Simply call `var barcode = await BarcodeScanner.scan()` to scan a barcode
|
2017-10-30 07:35:38 +08:00
|
|
|
class BarcodeScanner {
|
2020-02-20 06:36:18 +08:00
|
|
|
/// If the user has not granted the access to the camera this code is thrown.
|
2018-01-10 21:55:58 +08:00
|
|
|
static const CameraAccessDenied = 'PERMISSION_NOT_GRANTED';
|
2020-02-20 06:36:18 +08:00
|
|
|
|
|
|
|
/// If the user cancel the scan an exception with this code is thrown.
|
2019-07-23 01:11:27 +08:00
|
|
|
static const UserCanceled = 'USER_CANCELED';
|
2020-02-20 06:36:18 +08:00
|
|
|
|
|
|
|
/// The method channel
|
2017-10-30 01:05:11 +08:00
|
|
|
static const MethodChannel _channel =
|
2020-02-20 06:19:14 +08:00
|
|
|
const MethodChannel('de.mintware.barcode_scan');
|
2020-02-20 06:36:18 +08:00
|
|
|
|
|
|
|
/// Starts the camera for scanning the barcode, shows a preview window and
|
|
|
|
/// returns the barcode if one was scanned.
|
|
|
|
/// Can throw an exception.
|
|
|
|
/// See also [CameraAccessDenied] and [UserCanceled]
|
2017-10-30 01:05:11 +08:00
|
|
|
static Future<String> scan() async => await _channel.invokeMethod('scan');
|
|
|
|
}
|