Navaron Bracke

format

... ... @@ -31,7 +31,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
Stream<Map<Object?, Object?>>? _eventsStream;
Stream<Map<Object?, Object?>> get eventsStream {
_eventsStream ??= eventChannel.receiveBroadcastStream().cast<Map<Object?, Object?>>();
_eventsStream ??=
eventChannel.receiveBroadcastStream().cast<Map<Object?, Object?>>();
return _eventsStream!;
}
... ... @@ -50,7 +51,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
return null;
}
final List<Map<Object?, Object?>> barcodes = data.cast<Map<Object?, Object?>>();
final List<Map<Object?, Object?>> barcodes =
data.cast<Map<Object?, Object?>>();
if (Platform.isMacOS) {
return BarcodeCapture(
... ... @@ -119,7 +121,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
return; // Already authorized.
case MobileScannerAuthorizationState.undetermined:
try {
final bool permissionResult = await methodChannel.invokeMethod<bool>('request') ?? false;
final bool permissionResult =
await methodChannel.invokeMethod<bool>('request') ?? false;
if (permissionResult) {
return; // Authorization was granted.
... ... @@ -144,7 +147,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
@override
Stream<BarcodeCapture?> get barcodesStream {
return eventsStream.where((event) => event['name'] == 'barcode').map((event) => _parseBarcode(event));
return eventsStream
.where((event) => event['name'] == 'barcode')
.map((event) => _parseBarcode(event));
}
@override
... ... @@ -163,7 +168,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
@override
Future<BarcodeCapture?> analyzeImage(String path) async {
final Map<String, Object?>? result = await methodChannel.invokeMapMethod<String, Object?>(
final Map<String, Object?>? result =
await methodChannel.invokeMapMethod<String, Object?>(
'analyzeImage',
path,
);
... ... @@ -177,7 +183,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerUninitialized,
errorDetails: MobileScannerErrorDetails(
message: 'The controller was not yet initialized. Call start() before calling buildCameraView().',
message:
'The controller was not yet initialized. Call start() before calling buildCameraView().',
),
);
}
... ... @@ -210,7 +217,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
errorDetails: MobileScannerErrorDetails(
message: 'The scanner was already started. Call stop() before calling start() again.',
message:
'The scanner was already started. Call stop() before calling start() again.',
),
);
}
... ... @@ -259,7 +267,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
final bool hasTorch = startResult['torchable'] as bool? ?? false;
final Map<Object?, Object?>? sizeInfo = startResult['size'] as Map<Object?, Object?>?;
final Map<Object?, Object?>? sizeInfo =
startResult['size'] as Map<Object?, Object?>?;
final double? width = sizeInfo?['width'] as double?;
final double? height = sizeInfo?['height'] as double?;
... ...
... ... @@ -81,7 +81,10 @@ class _MobileScannerState extends State<MobileScanner> {
Rect? scanWindow;
/// Recalculate the scan window based on the updated [constraints].
void _maybeUpdateScanWindow(MobileScannerState scannerState, BoxConstraints constraints) {
void _maybeUpdateScanWindow(
MobileScannerState scannerState,
BoxConstraints constraints,
) {
if (widget.scanWindow != null && scanWindow == null) {
scanWindow = calculateScanWindowRelativeToTextureInPercentage(
widget.fit,
... ... @@ -102,7 +105,8 @@ class _MobileScannerState extends State<MobileScanner> {
if (!value.isInitialized) {
const Widget defaultPlaceholder = ColoredBox(color: Colors.black);
return widget.placeholderBuilder?.call(context, child) ?? defaultPlaceholder;
return widget.placeholderBuilder?.call(context, child) ??
defaultPlaceholder;
}
final MobileScannerException? error = value.error;
... ... @@ -113,14 +117,16 @@ class _MobileScannerState extends State<MobileScanner> {
child: Center(child: Icon(Icons.error, color: Colors.white)),
);
return widget.errorBuilder?.call(context, error, child) ?? defaultError;
return widget.errorBuilder?.call(context, error, child) ??
defaultError;
}
return LayoutBuilder(
builder: (context, constraints) {
_maybeUpdateScanWindow(value, constraints);
final Widget? overlay = widget.overlayBuilder?.call(context, constraints);
final Widget? overlay =
widget.overlayBuilder?.call(context, constraints);
final Size cameraPreviewSize = value.size;
final Widget scannerWidget = ClipRect(
... ...
... ... @@ -25,8 +25,12 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
this.returnImage = false,
this.torchEnabled = false,
this.useNewCameraSelector = false,
}) : detectionTimeoutMs = detectionSpeed == DetectionSpeed.normal ? detectionTimeoutMs : 0,
assert(detectionTimeoutMs >= 0, 'The detection timeout must be greater than or equal to 0.'),
}) : detectionTimeoutMs =
detectionSpeed == DetectionSpeed.normal ? detectionTimeoutMs : 0,
assert(
detectionTimeoutMs >= 0,
'The detection timeout must be greater than or equal to 0.',
),
super(MobileScannerState.uninitialized(facing));
/// The desired resolution for the camera.
... ... @@ -90,7 +94,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
final bool useNewCameraSelector;
/// The internal barcode controller, that listens for detected barcodes.
final StreamController<BarcodeCapture> _barcodesController = StreamController.broadcast();
final StreamController<BarcodeCapture> _barcodesController =
StreamController.broadcast();
/// Get the stream of scanned barcodes.
Stream<BarcodeCapture> get barcodes => _barcodesController.stream;
... ... @@ -112,17 +117,20 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
}
void _setupListeners() {
_barcodesSubscription = MobileScannerPlatform.instance.barcodesStream.listen((BarcodeCapture? barcode) {
_barcodesSubscription = MobileScannerPlatform.instance.barcodesStream
.listen((BarcodeCapture? barcode) {
if (barcode != null) {
_barcodesController.add(barcode);
}
});
_torchStateSubscription = MobileScannerPlatform.instance.torchStateStream.listen((TorchState torchState) {
_torchStateSubscription = MobileScannerPlatform.instance.torchStateStream
.listen((TorchState torchState) {
value = value.copyWith(torchState: torchState);
});
_zoomScaleSubscription = MobileScannerPlatform.instance.zoomScaleStateStream.listen((double zoomScale) {
_zoomScaleSubscription = MobileScannerPlatform.instance.zoomScaleStateStream
.listen((double zoomScale) {
value = value.copyWith(zoomScale: zoomScale);
});
}
... ... @@ -141,7 +149,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerDisposed,
errorDetails: MobileScannerErrorDetails(
message: 'The MobileScannerController was used after it has been disposed.',
message:
'The MobileScannerController was used after it has been disposed.',
),
);
}
... ... @@ -203,7 +212,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerDisposed,
errorDetails: MobileScannerErrorDetails(
message: 'The MobileScannerController was used after it has been disposed.',
message:
'The MobileScannerController was used after it has been disposed.',
),
);
}
... ... @@ -223,7 +233,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
try {
_setupListeners();
final MobileScannerViewAttributes viewAttributes = await MobileScannerPlatform.instance.start(
final MobileScannerViewAttributes viewAttributes =
await MobileScannerPlatform.instance.start(
options,
);
... ... @@ -275,7 +286,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
final CameraFacing cameraDirection = value.cameraDirection;
await start(
cameraDirection: cameraDirection == CameraFacing.front ? CameraFacing.back : CameraFacing.front,
cameraDirection: cameraDirection == CameraFacing.front
? CameraFacing.back
: CameraFacing.front,
);
}
... ... @@ -291,7 +304,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
return;
}
final TorchState newState = torchState == TorchState.off ? TorchState.on : TorchState.off;
final TorchState newState =
torchState == TorchState.off ? TorchState.on : TorchState.off;
// Update the torch state to the new state.
// When the platform has updated the torch state,
... ...
... ... @@ -10,8 +10,10 @@ void main() {
2: MobileScannerAuthorizationState.denied,
};
for (final MapEntry<int, MobileScannerAuthorizationState> entry in values.entries) {
final MobileScannerAuthorizationState result = MobileScannerAuthorizationState.fromRawValue(
for (final MapEntry<int, MobileScannerAuthorizationState> entry
in values.entries) {
final MobileScannerAuthorizationState result =
MobileScannerAuthorizationState.fromRawValue(
entry.key,
);
... ... @@ -40,7 +42,8 @@ void main() {
MobileScannerAuthorizationState.denied: 2,
};
for (final MapEntry<MobileScannerAuthorizationState, int> entry in values.entries) {
for (final MapEntry<MobileScannerAuthorizationState, int> entry
in values.entries) {
final int result = entry.key.rawValue;
expect(result, entry.value);
... ...