Navaron Bracke
Committed by GitHub

Merge pull request #813 from navaronbracke/reorganise_classes

feat: Reorganise enums
export 'src/enums/address_type.dart';
export 'src/enums/barcode_format.dart';
export 'src/enums/barcode_type.dart';
export 'src/enums/camera_facing.dart';
export 'src/enums/detection_speed.dart';
export 'src/enums/email_type.dart';
export 'src/enums/encryption_type.dart';
export 'src/enums/mobile_scanner_error_code.dart';
export 'src/enums/mobile_scanner_state.dart';
export 'src/enums/ratio.dart';
export 'src/enums/phone_type.dart';
export 'src/enums/torch_state.dart';
export 'src/mobile_scanner.dart';
export 'src/mobile_scanner_controller.dart';
... ...
... ... @@ -6,8 +6,8 @@ import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:mobile_scanner/mobile_scanner_web.dart';
import 'package:mobile_scanner/src/barcode_utility.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
import 'package:mobile_scanner/src/objects/barcode.dart';
/// This plugin is the web implementation of mobile_scanner.
/// It only supports QR codes.
... ...
/// Address type constants.
enum AddressType {
/// Unknown address type.
unknown(0),
/// Work address.
work(1),
/// Home address.
home(2);
const AddressType(this.rawValue);
factory AddressType.fromRawValue(int value) {
switch (value) {
case 1:
return AddressType.work;
case 2:
return AddressType.home;
case 0:
default:
return AddressType.unknown;
}
}
/// The raw address type value.
final int rawValue;
}
... ...
/// This enum defines the different barcode formats.
enum BarcodeFormat {
/// A barcode format that represents all unknown formats.
unknown(-1),
/// A barcode format that represents all known formats.
all(0),
/// Barcode format constant for Code 128.
code128(1),
/// Barcode format constant for Code 39.
code39(2),
/// Barcode format constant for Code 93.
code93(4),
/// Barcode format constant for Codabar.
codebar(8),
/// Barcode format constant for Data Matrix.
dataMatrix(16),
/// Barcode format constant for EAN-13.
ean13(32),
/// Barcode format constant for EAN-8.
ean8(64),
/// Barcode format constant for ITF (Interleaved Two-of-Five).
itf(128),
/// Barcode format constant for QR Codes.
qrCode(256),
/// Barcode format constant for UPC-A.
upcA(512),
/// Barcode format constant for UPC-E.
upcE(1024),
/// Barcode format constant for PDF-417.
pdf417(2048),
/// Barcode format constant for AZTEC.
aztec(4096);
const BarcodeFormat(this.rawValue);
factory BarcodeFormat.fromRawValue(int value) {
switch (value) {
case 0:
return BarcodeFormat.all;
case 1:
return BarcodeFormat.code128;
case 2:
return BarcodeFormat.code39;
case 4:
return BarcodeFormat.code93;
case 8:
return BarcodeFormat.codebar;
case 16:
return BarcodeFormat.dataMatrix;
case 32:
return BarcodeFormat.ean13;
case 64:
return BarcodeFormat.ean8;
case 128:
return BarcodeFormat.itf;
case 256:
return BarcodeFormat.qrCode;
case 512:
return BarcodeFormat.upcA;
case 1024:
return BarcodeFormat.upcE;
case 2048:
return BarcodeFormat.pdf417;
case 4096:
return BarcodeFormat.aztec;
case -1:
default:
return BarcodeFormat.unknown;
}
}
/// The raw value of the barcode format.
final int rawValue;
}
... ...
/// Barcode value type constants.
enum BarcodeType {
/// An unknown barcode type.
unknown(0),
/// Barcode value type constant for contact information.
contactInfo(1),
/// Barcode value type constant for email message details.
email(2),
/// Barcode value type constant for ISBNs.
isbn(3),
/// Barcode value type constant for phone numbers.
phone(4),
/// Barcode value type constant for product codes.
product(5),
/// Barcode value type constant for SMS details.
sms(6),
/// Barcode value type constant for plain text.
text(7),
/// Barcode value type constant for URLs or bookmarks.
url(8),
/// Barcode value type constant for WiFi access point details.
wifi(9),
/// Barcode value type constant for geographic coordinates.
geo(10),
/// Barcode value type constant for calendar events.
calendarEvent(11),
/// Barcode value type constant for driver license data.
driverLicense(12);
const BarcodeType(this.rawValue);
factory BarcodeType.fromRawValue(int value) {
switch (value) {
case 1:
return BarcodeType.contactInfo;
case 2:
return BarcodeType.email;
case 3:
return BarcodeType.isbn;
case 4:
return BarcodeType.phone;
case 5:
return BarcodeType.product;
case 6:
return BarcodeType.sms;
case 7:
return BarcodeType.text;
case 8:
return BarcodeType.url;
case 9:
return BarcodeType.wifi;
case 10:
return BarcodeType.geo;
case 11:
return BarcodeType.calendarEvent;
case 12:
return BarcodeType.driverLicense;
case 0:
default:
return BarcodeType.unknown;
}
}
/// The raw barcode type value.
final int rawValue;
}
... ...
/// The facing of a camera.
enum CameraFacing {
/// Front facing camera.
front,
front(0),
/// Back facing camera.
back,
back(1);
const CameraFacing(this.rawValue);
/// The raw value for the camera facing direction.
final int rawValue;
}
... ...
... ... @@ -5,16 +5,21 @@ enum DetectionSpeed {
///
/// NOTE: This mode does analyze every frame in order to check if the value
/// has changed.
noDuplicates,
noDuplicates(0),
/// The barcode scanner will scan one barcode, and wait 250 Miliseconds before
/// scanning again. This will prevent memory issues on older devices.
///
/// You can change the timeout duration with [detectionTimeout] parameter.
normal,
normal(1),
/// Let the scanner detect barcodes without restriction.
///
/// NOTE: This can cause memory issues with older devices.
unrestricted,
unrestricted(2);
const DetectionSpeed(this.rawValue);
/// The raw value for the detection speed.
final int rawValue;
}
... ...
/// Email format type constants.
enum EmailType {
/// Unknown email type.
unknown(0),
/// Work email.
work(1),
/// Home email.
home(2);
const EmailType(this.rawValue);
factory EmailType.fromRawValue(int value) {
switch (value) {
case 1:
return EmailType.work;
case 2:
return EmailType.home;
case 0:
default:
return EmailType.unknown;
}
}
/// The raw email type value.
final int rawValue;
}
... ...
/// Wifi encryption type constants.
enum EncryptionType {
/// Unknown encryption type.
none(0),
/// Not encrypted.
open(1),
/// WPA level encryption.
wpa(2),
/// WEP level encryption.
wep(3);
const EncryptionType(this.rawValue);
factory EncryptionType.fromRawValue(int value) {
switch (value) {
case 1:
return EncryptionType.open;
case 2:
return EncryptionType.wpa;
case 3:
return EncryptionType.wep;
case 0:
default:
return EncryptionType.none;
}
}
/// The raw value for the encryption type.
final int rawValue;
}
... ...
/// The authorization state of the scanner.
enum MobileScannerState {
/// The scanner has not yet requested the required permissions.
undetermined,
undetermined(0),
/// The scanner has the required permissions.
authorized,
authorized(1),
/// The user denied the required permissions.
denied
denied(2);
const MobileScannerState(this.rawValue);
factory MobileScannerState.fromRawValue(int value) {
switch (value) {
case 0:
return MobileScannerState.undetermined;
case 1:
return MobileScannerState.authorized;
case 2:
return MobileScannerState.denied;
default:
throw ArgumentError.value(value, 'value', 'Invalid raw value.');
}
}
/// The raw value for the state.
final int rawValue;
}
... ...
/// Phone number format type constants.
enum PhoneType {
/// Unknown phone type.
unknown(0),
/// Work phone.
work(1),
/// Home phone.
home(2),
/// Fax machine.
fax(3),
/// Mobile phone.
mobile(4);
const PhoneType(this.rawValue);
factory PhoneType.fromRawValue(int value) {
switch (value) {
case 1:
return PhoneType.work;
case 2:
return PhoneType.home;
case 3:
return PhoneType.fax;
case 4:
return PhoneType.mobile;
case 0:
default:
return PhoneType.unknown;
}
}
/// The raw phone type value.
final int rawValue;
}
... ...
// This enum is not used yet
// enum Ratio { ratio_4_3, ratio_16_9 }
/// The state of torch.
/// The state of the flashlight.
enum TorchState {
/// Torch is off.
off,
/// The flashlight is off.
off(0),
/// Torch is on.
on,
/// The flashlight is on.
on(1);
const TorchState(this.rawValue);
/// The raw value for the torch state.
final int rawValue;
}
... ...
... ... @@ -2,6 +2,12 @@ import 'dart:typed_data';
import 'dart:ui';
import 'package:mobile_scanner/src/barcode_utility.dart';
import 'package:mobile_scanner/src/enums/address_type.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/barcode_type.dart';
import 'package:mobile_scanner/src/enums/email_type.dart';
import 'package:mobile_scanner/src/enums/encryption_type.dart';
import 'package:mobile_scanner/src/enums/phone_type.dart';
/// Represents a single recognized barcode and its value.
class Barcode {
... ... @@ -500,272 +506,3 @@ class WiFi {
ssid = data['ssid'] as String?,
password = data['password'] as String?;
}
enum BarcodeFormat {
/// Barcode format unknown to the current SDK.
///
/// Constant Value: -1
unknown,
/// Barcode format constant representing the union of all supported formats.
///
/// Constant Value: 0
all,
/// Barcode format constant for Code 128.
///
/// Constant Value: 1
code128,
/// Barcode format constant for Code 39.
///
/// Constant Value: 2
code39,
/// Barcode format constant for Code 93.
///
/// Constant Value: 4
code93,
/// Barcode format constant for Codabar.
///
/// Constant Value: 8
codebar,
/// Barcode format constant for Data Matrix.
///
/// Constant Value: 16
dataMatrix,
/// Barcode format constant for EAN-13.
///
/// Constant Value: 32
ean13,
/// Barcode format constant for EAN-8.
///
/// Constant Value: 64
ean8,
/// Barcode format constant for ITF (Interleaved Two-of-Five).
///
/// Constant Value: 128
itf,
/// Barcode format constant for QR Code.
///
/// Constant Value: 256
qrCode,
/// Barcode format constant for UPC-A.
///
/// Constant Value: 512
upcA,
/// Barcode format constant for UPC-E.
///
/// Constant Value: 1024
upcE,
/// Barcode format constant for PDF-417.
///
/// Constant Value: 2048
pdf417,
/// Barcode format constant for AZTEC.
///
/// Constant Value: 4096
aztec,
}
extension BarcodeValue on BarcodeFormat {
int get rawValue {
switch (this) {
case BarcodeFormat.unknown:
return -1;
case BarcodeFormat.all:
return 0;
case BarcodeFormat.code128:
return 1;
case BarcodeFormat.code39:
return 2;
case BarcodeFormat.code93:
return 4;
case BarcodeFormat.codebar:
return 8;
case BarcodeFormat.dataMatrix:
return 16;
case BarcodeFormat.ean13:
return 32;
case BarcodeFormat.ean8:
return 64;
case BarcodeFormat.itf:
return 128;
case BarcodeFormat.qrCode:
return 256;
case BarcodeFormat.upcA:
return 512;
case BarcodeFormat.upcE:
return 1024;
case BarcodeFormat.pdf417:
return 2048;
case BarcodeFormat.aztec:
return 4096;
}
}
}
/// Address type constants.
enum AddressType {
/// Unknown address type.
///
/// Constant Value: 0
unknown,
/// Work address.
///
/// Constant Value: 1
work,
/// Home address.
///
/// Constant Value: 2
home,
}
/// Barcode value type constants
enum BarcodeType {
/// Barcode value type unknown, which indicates the current version of SDK cannot recognize the structure of the barcode. Developers can inspect the raw value instead.
///
/// Constant Value: 0
unknown,
/// Barcode value type constant for contact information.
///
/// Constant Value: 1
contactInfo,
/// Barcode value type constant for email message details.
///
/// Constant Value: 2
email,
/// Barcode value type constant for ISBNs.
///
/// Constant Value: 3
isbn,
/// Barcode value type constant for phone numbers.
///
/// Constant Value: 4
phone,
/// Barcode value type constant for product codes.
///
/// Constant Value: 5
product,
/// Barcode value type constant for SMS details.
///
/// Constant Value: 6
sms,
/// Barcode value type constant for plain text.
///
///Constant Value: 7
text,
/// Barcode value type constant for URLs/bookmarks.
///
/// Constant Value: 8
url,
/// Barcode value type constant for WiFi access point details.
///
/// Constant Value: 9
wifi,
/// Barcode value type constant for geographic coordinates.
///
/// Constant Value: 10
geo,
/// Barcode value type constant for calendar events.
///
/// Constant Value: 11
calendarEvent,
/// Barcode value type constant for driver's license data.
///
/// Constant Value: 12
driverLicense,
}
/// Email format type constants.
enum EmailType {
/// Unknown email type.
///
/// Constant Value: 0
unknown,
/// Work email.
///
/// Constant Value: 1
work,
/// Home email.
///
/// Constant Value: 2
home,
}
/// Phone number format type constants.
enum PhoneType {
/// Unknown phone type.
///
/// Constant Value: 0
unknown,
/// Work phone.
///
/// Constant Value: 1
work,
/// Home phone.
///
/// Constant Value: 2
home,
/// Fax machine.
///
/// Constant Value: 3
fax,
/// Mobile phone.
///
/// Constant Value: 4
mobile,
}
/// Wifi encryption type constants.
enum EncryptionType {
/// Unknown encryption type.
///
/// Constant Value: 0
none,
/// Not encrypted.
///
/// Constant Value: 1
open,
/// WPA level encryption.
///
/// Constant Value: 2
wpa,
/// WEP level encryption.
///
/// Constant Value: 3
wep,
}
... ...
... ... @@ -3,6 +3,7 @@ import 'dart:html' as html;
import 'package:flutter/material.dart';
import 'package:js/js.dart';
import 'package:js/js_util.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
import 'package:mobile_scanner/src/objects/barcode.dart';
import 'package:mobile_scanner/src/web/media.dart';
... ...
... ... @@ -6,6 +6,7 @@ import 'dart:html';
import 'dart:typed_data';
import 'package:js/js.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
import 'package:mobile_scanner/src/objects/barcode.dart';
import 'package:mobile_scanner/src/web/base.dart';
... ...
... ... @@ -4,6 +4,7 @@ import 'dart:typed_data';
import 'dart:ui';
import 'package:js/js.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
import 'package:mobile_scanner/src/objects/barcode.dart';
import 'package:mobile_scanner/src/web/base.dart';
... ...