Navaron Bracke

format

@@ -31,7 +31,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -31,7 +31,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
31 Stream<Map<Object?, Object?>>? _eventsStream; 31 Stream<Map<Object?, Object?>>? _eventsStream;
32 32
33 Stream<Map<Object?, Object?>> get eventsStream { 33 Stream<Map<Object?, Object?>> get eventsStream {
34 - _eventsStream ??= eventChannel.receiveBroadcastStream().cast<Map<Object?, Object?>>(); 34 + _eventsStream ??=
  35 + eventChannel.receiveBroadcastStream().cast<Map<Object?, Object?>>();
35 36
36 return _eventsStream!; 37 return _eventsStream!;
37 } 38 }
@@ -50,7 +51,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -50,7 +51,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
50 return null; 51 return null;
51 } 52 }
52 53
53 - final List<Map<Object?, Object?>> barcodes = data.cast<Map<Object?, Object?>>(); 54 + final List<Map<Object?, Object?>> barcodes =
  55 + data.cast<Map<Object?, Object?>>();
54 56
55 if (Platform.isMacOS) { 57 if (Platform.isMacOS) {
56 return BarcodeCapture( 58 return BarcodeCapture(
@@ -119,7 +121,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -119,7 +121,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
119 return; // Already authorized. 121 return; // Already authorized.
120 case MobileScannerAuthorizationState.undetermined: 122 case MobileScannerAuthorizationState.undetermined:
121 try { 123 try {
122 - final bool permissionResult = await methodChannel.invokeMethod<bool>('request') ?? false; 124 + final bool permissionResult =
  125 + await methodChannel.invokeMethod<bool>('request') ?? false;
123 126
124 if (permissionResult) { 127 if (permissionResult) {
125 return; // Authorization was granted. 128 return; // Authorization was granted.
@@ -144,7 +147,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -144,7 +147,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
144 147
145 @override 148 @override
146 Stream<BarcodeCapture?> get barcodesStream { 149 Stream<BarcodeCapture?> get barcodesStream {
147 - return eventsStream.where((event) => event['name'] == 'barcode').map((event) => _parseBarcode(event)); 150 + return eventsStream
  151 + .where((event) => event['name'] == 'barcode')
  152 + .map((event) => _parseBarcode(event));
148 } 153 }
149 154
150 @override 155 @override
@@ -163,7 +168,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -163,7 +168,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
163 168
164 @override 169 @override
165 Future<BarcodeCapture?> analyzeImage(String path) async { 170 Future<BarcodeCapture?> analyzeImage(String path) async {
166 - final Map<String, Object?>? result = await methodChannel.invokeMapMethod<String, Object?>( 171 + final Map<String, Object?>? result =
  172 + await methodChannel.invokeMapMethod<String, Object?>(
167 'analyzeImage', 173 'analyzeImage',
168 path, 174 path,
169 ); 175 );
@@ -177,7 +183,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -177,7 +183,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
177 throw const MobileScannerException( 183 throw const MobileScannerException(
178 errorCode: MobileScannerErrorCode.controllerUninitialized, 184 errorCode: MobileScannerErrorCode.controllerUninitialized,
179 errorDetails: MobileScannerErrorDetails( 185 errorDetails: MobileScannerErrorDetails(
180 - message: 'The controller was not yet initialized. Call start() before calling buildCameraView().', 186 + message:
  187 + 'The controller was not yet initialized. Call start() before calling buildCameraView().',
181 ), 188 ),
182 ); 189 );
183 } 190 }
@@ -210,7 +217,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -210,7 +217,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
210 throw const MobileScannerException( 217 throw const MobileScannerException(
211 errorCode: MobileScannerErrorCode.controllerAlreadyInitialized, 218 errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
212 errorDetails: MobileScannerErrorDetails( 219 errorDetails: MobileScannerErrorDetails(
213 - message: 'The scanner was already started. Call stop() before calling start() again.', 220 + message:
  221 + 'The scanner was already started. Call stop() before calling start() again.',
214 ), 222 ),
215 ); 223 );
216 } 224 }
@@ -259,7 +267,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -259,7 +267,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
259 267
260 final bool hasTorch = startResult['torchable'] as bool? ?? false; 268 final bool hasTorch = startResult['torchable'] as bool? ?? false;
261 269
262 - final Map<Object?, Object?>? sizeInfo = startResult['size'] as Map<Object?, Object?>?; 270 + final Map<Object?, Object?>? sizeInfo =
  271 + startResult['size'] as Map<Object?, Object?>?;
263 final double? width = sizeInfo?['width'] as double?; 272 final double? width = sizeInfo?['width'] as double?;
264 final double? height = sizeInfo?['height'] as double?; 273 final double? height = sizeInfo?['height'] as double?;
265 274
@@ -81,7 +81,10 @@ class _MobileScannerState extends State<MobileScanner> { @@ -81,7 +81,10 @@ class _MobileScannerState extends State<MobileScanner> {
81 Rect? scanWindow; 81 Rect? scanWindow;
82 82
83 /// Recalculate the scan window based on the updated [constraints]. 83 /// Recalculate the scan window based on the updated [constraints].
84 - void _maybeUpdateScanWindow(MobileScannerState scannerState, BoxConstraints constraints) { 84 + void _maybeUpdateScanWindow(
  85 + MobileScannerState scannerState,
  86 + BoxConstraints constraints,
  87 + ) {
85 if (widget.scanWindow != null && scanWindow == null) { 88 if (widget.scanWindow != null && scanWindow == null) {
86 scanWindow = calculateScanWindowRelativeToTextureInPercentage( 89 scanWindow = calculateScanWindowRelativeToTextureInPercentage(
87 widget.fit, 90 widget.fit,
@@ -102,7 +105,8 @@ class _MobileScannerState extends State<MobileScanner> { @@ -102,7 +105,8 @@ class _MobileScannerState extends State<MobileScanner> {
102 if (!value.isInitialized) { 105 if (!value.isInitialized) {
103 const Widget defaultPlaceholder = ColoredBox(color: Colors.black); 106 const Widget defaultPlaceholder = ColoredBox(color: Colors.black);
104 107
105 - return widget.placeholderBuilder?.call(context, child) ?? defaultPlaceholder; 108 + return widget.placeholderBuilder?.call(context, child) ??
  109 + defaultPlaceholder;
106 } 110 }
107 111
108 final MobileScannerException? error = value.error; 112 final MobileScannerException? error = value.error;
@@ -113,14 +117,16 @@ class _MobileScannerState extends State<MobileScanner> { @@ -113,14 +117,16 @@ class _MobileScannerState extends State<MobileScanner> {
113 child: Center(child: Icon(Icons.error, color: Colors.white)), 117 child: Center(child: Icon(Icons.error, color: Colors.white)),
114 ); 118 );
115 119
116 - return widget.errorBuilder?.call(context, error, child) ?? defaultError; 120 + return widget.errorBuilder?.call(context, error, child) ??
  121 + defaultError;
117 } 122 }
118 123
119 return LayoutBuilder( 124 return LayoutBuilder(
120 builder: (context, constraints) { 125 builder: (context, constraints) {
121 _maybeUpdateScanWindow(value, constraints); 126 _maybeUpdateScanWindow(value, constraints);
122 127
123 - final Widget? overlay = widget.overlayBuilder?.call(context, constraints); 128 + final Widget? overlay =
  129 + widget.overlayBuilder?.call(context, constraints);
124 final Size cameraPreviewSize = value.size; 130 final Size cameraPreviewSize = value.size;
125 131
126 final Widget scannerWidget = ClipRect( 132 final Widget scannerWidget = ClipRect(
@@ -25,8 +25,12 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -25,8 +25,12 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
25 this.returnImage = false, 25 this.returnImage = false,
26 this.torchEnabled = false, 26 this.torchEnabled = false,
27 this.useNewCameraSelector = false, 27 this.useNewCameraSelector = false,
28 - }) : detectionTimeoutMs = detectionSpeed == DetectionSpeed.normal ? detectionTimeoutMs : 0,  
29 - assert(detectionTimeoutMs >= 0, 'The detection timeout must be greater than or equal to 0.'), 28 + }) : detectionTimeoutMs =
  29 + detectionSpeed == DetectionSpeed.normal ? detectionTimeoutMs : 0,
  30 + assert(
  31 + detectionTimeoutMs >= 0,
  32 + 'The detection timeout must be greater than or equal to 0.',
  33 + ),
30 super(MobileScannerState.uninitialized(facing)); 34 super(MobileScannerState.uninitialized(facing));
31 35
32 /// The desired resolution for the camera. 36 /// The desired resolution for the camera.
@@ -90,7 +94,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -90,7 +94,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
90 final bool useNewCameraSelector; 94 final bool useNewCameraSelector;
91 95
92 /// The internal barcode controller, that listens for detected barcodes. 96 /// The internal barcode controller, that listens for detected barcodes.
93 - final StreamController<BarcodeCapture> _barcodesController = StreamController.broadcast(); 97 + final StreamController<BarcodeCapture> _barcodesController =
  98 + StreamController.broadcast();
94 99
95 /// Get the stream of scanned barcodes. 100 /// Get the stream of scanned barcodes.
96 Stream<BarcodeCapture> get barcodes => _barcodesController.stream; 101 Stream<BarcodeCapture> get barcodes => _barcodesController.stream;
@@ -112,17 +117,20 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -112,17 +117,20 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
112 } 117 }
113 118
114 void _setupListeners() { 119 void _setupListeners() {
115 - _barcodesSubscription = MobileScannerPlatform.instance.barcodesStream.listen((BarcodeCapture? barcode) { 120 + _barcodesSubscription = MobileScannerPlatform.instance.barcodesStream
  121 + .listen((BarcodeCapture? barcode) {
116 if (barcode != null) { 122 if (barcode != null) {
117 _barcodesController.add(barcode); 123 _barcodesController.add(barcode);
118 } 124 }
119 }); 125 });
120 126
121 - _torchStateSubscription = MobileScannerPlatform.instance.torchStateStream.listen((TorchState torchState) { 127 + _torchStateSubscription = MobileScannerPlatform.instance.torchStateStream
  128 + .listen((TorchState torchState) {
122 value = value.copyWith(torchState: torchState); 129 value = value.copyWith(torchState: torchState);
123 }); 130 });
124 131
125 - _zoomScaleSubscription = MobileScannerPlatform.instance.zoomScaleStateStream.listen((double zoomScale) { 132 + _zoomScaleSubscription = MobileScannerPlatform.instance.zoomScaleStateStream
  133 + .listen((double zoomScale) {
126 value = value.copyWith(zoomScale: zoomScale); 134 value = value.copyWith(zoomScale: zoomScale);
127 }); 135 });
128 } 136 }
@@ -141,7 +149,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -141,7 +149,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
141 throw const MobileScannerException( 149 throw const MobileScannerException(
142 errorCode: MobileScannerErrorCode.controllerDisposed, 150 errorCode: MobileScannerErrorCode.controllerDisposed,
143 errorDetails: MobileScannerErrorDetails( 151 errorDetails: MobileScannerErrorDetails(
144 - message: 'The MobileScannerController was used after it has been disposed.', 152 + message:
  153 + 'The MobileScannerController was used after it has been disposed.',
145 ), 154 ),
146 ); 155 );
147 } 156 }
@@ -203,7 +212,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -203,7 +212,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
203 throw const MobileScannerException( 212 throw const MobileScannerException(
204 errorCode: MobileScannerErrorCode.controllerDisposed, 213 errorCode: MobileScannerErrorCode.controllerDisposed,
205 errorDetails: MobileScannerErrorDetails( 214 errorDetails: MobileScannerErrorDetails(
206 - message: 'The MobileScannerController was used after it has been disposed.', 215 + message:
  216 + 'The MobileScannerController was used after it has been disposed.',
207 ), 217 ),
208 ); 218 );
209 } 219 }
@@ -223,7 +233,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -223,7 +233,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
223 try { 233 try {
224 _setupListeners(); 234 _setupListeners();
225 235
226 - final MobileScannerViewAttributes viewAttributes = await MobileScannerPlatform.instance.start( 236 + final MobileScannerViewAttributes viewAttributes =
  237 + await MobileScannerPlatform.instance.start(
227 options, 238 options,
228 ); 239 );
229 240
@@ -275,7 +286,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -275,7 +286,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
275 final CameraFacing cameraDirection = value.cameraDirection; 286 final CameraFacing cameraDirection = value.cameraDirection;
276 287
277 await start( 288 await start(
278 - cameraDirection: cameraDirection == CameraFacing.front ? CameraFacing.back : CameraFacing.front, 289 + cameraDirection: cameraDirection == CameraFacing.front
  290 + ? CameraFacing.back
  291 + : CameraFacing.front,
279 ); 292 );
280 } 293 }
281 294
@@ -291,7 +304,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -291,7 +304,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
291 return; 304 return;
292 } 305 }
293 306
294 - final TorchState newState = torchState == TorchState.off ? TorchState.on : TorchState.off; 307 + final TorchState newState =
  308 + torchState == TorchState.off ? TorchState.on : TorchState.off;
295 309
296 // Update the torch state to the new state. 310 // Update the torch state to the new state.
297 // When the platform has updated the torch state, 311 // When the platform has updated the torch state,
@@ -10,8 +10,10 @@ void main() { @@ -10,8 +10,10 @@ void main() {
10 2: MobileScannerAuthorizationState.denied, 10 2: MobileScannerAuthorizationState.denied,
11 }; 11 };
12 12
13 - for (final MapEntry<int, MobileScannerAuthorizationState> entry in values.entries) {  
14 - final MobileScannerAuthorizationState result = MobileScannerAuthorizationState.fromRawValue( 13 + for (final MapEntry<int, MobileScannerAuthorizationState> entry
  14 + in values.entries) {
  15 + final MobileScannerAuthorizationState result =
  16 + MobileScannerAuthorizationState.fromRawValue(
15 entry.key, 17 entry.key,
16 ); 18 );
17 19
@@ -40,7 +42,8 @@ void main() { @@ -40,7 +42,8 @@ void main() {
40 MobileScannerAuthorizationState.denied: 2, 42 MobileScannerAuthorizationState.denied: 2,
41 }; 43 };
42 44
43 - for (final MapEntry<MobileScannerAuthorizationState, int> entry in values.entries) { 45 + for (final MapEntry<MobileScannerAuthorizationState, int> entry
  46 + in values.entries) {
44 final int result = entry.key.rawValue; 47 final int result = entry.key.rawValue;
45 48
46 expect(result, entry.value); 49 expect(result, entry.value);