mobile_scanner_exception.dart
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart';
/// This class represents an exception thrown by the [MobileScannerController].
class MobileScannerException implements Exception {
const MobileScannerException({
required this.errorCode,
this.errorDetails,
});
/// The error code of the exception.
final MobileScannerErrorCode errorCode;
/// The additional error details that came with the [errorCode].
final MobileScannerErrorDetails? errorDetails;
@override
String toString() {
if (errorDetails != null && errorDetails?.message != null) {
return 'MobileScannerException(${errorCode.name}, ${errorDetails?.message})';
}
return 'MobileScannerException(${errorCode.name})';
}
}
/// The raw error details for a [MobileScannerException].
class MobileScannerErrorDetails {
const MobileScannerErrorDetails({
this.code,
this.details,
this.message,
});
/// The error code from the [PlatformException].
final String? code;
/// The details from the [PlatformException].
final Object? details;
/// The error message from the [PlatformException].
final String? message;
}
/// This class represents an exception thrown by the [MobileScannerController]
/// when a barcode scanning error occurs when processing an input frame.
class MobileScannerBarcodeException implements Exception {
/// Creates a new [MobileScannerBarcodeException] with the given error message.
const MobileScannerBarcodeException(this.message);
/// The error message of the exception.
final String? message;
@override
String toString() {
if (message?.isNotEmpty ?? false) {
return 'MobileScannerBarcodeException($message)';
}
return 'MobileScannerBarcodeException(Could not detect a barcode in the input image.)';
}
}