Skip to content

Commit 6cd552a

Browse files
Merge pull request juliansteenbakker#1565 from juliansteenbakker/fix/core_style
fix: core style
2 parents 7021469 + 2b94f18 commit 6cd552a

32 files changed

+256
-280
lines changed

analysis_options.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
include: package:very_good_analysis/analysis_options.yaml
2-
3-
linter:
4-
rules:
5-
omit_local_variable_types: false
6-
specify_nonobvious_local_variable_types: true

lib/src/method_channel/android_surface_producer_delegate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AndroidSurfaceProducerDelegate {
2828
'naturalDeviceOrientation': final String naturalDeviceOrientation,
2929
'sensorOrientation': final int sensorOrientation,
3030
}) {
31-
final DeviceOrientation naturalOrientation =
31+
final naturalOrientation =
3232
naturalDeviceOrientation.parseDeviceOrientation();
3333

3434
return AndroidSurfaceProducerDelegate(

lib/src/method_channel/mobile_scanner_method_channel.dart

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,21 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
8787
return null;
8888
}
8989

90-
final Object? data = event['data'];
90+
final data = event['data'];
9191

9292
if (data == null || data is! List<Object?>) {
9393
return null;
9494
}
9595

96-
final List<Map<Object?, Object?>> barcodes =
97-
data.cast<Map<Object?, Object?>>();
96+
final barcodes = data.cast<Map<Object?, Object?>>();
9897

9998
if (defaultTargetPlatform == TargetPlatform.android ||
10099
defaultTargetPlatform == TargetPlatform.iOS ||
101100
defaultTargetPlatform == TargetPlatform.macOS) {
102-
final Map<Object?, Object?>? imageData =
103-
event['image'] as Map<Object?, Object?>?;
104-
final Uint8List? image = imageData?['bytes'] as Uint8List?;
105-
final double? width = imageData?['width'] as double?;
106-
final double? height = imageData?['height'] as double?;
101+
final imageData = event['image'] as Map<Object?, Object?>?;
102+
final image = imageData?['bytes'] as Uint8List?;
103+
final width = imageData?['width'] as double?;
104+
final height = imageData?['height'] as double?;
107105

108106
return BarcodeCapture(
109107
raw: event,
@@ -143,10 +141,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
143141
/// Throws a [MobileScannerException] if the permission is not granted.
144142
Future<void> _requestCameraPermission() async {
145143
try {
146-
final MobileScannerAuthorizationState authorizationState =
147-
MobileScannerAuthorizationState.fromRawValue(
148-
await methodChannel.invokeMethod<int>('state') ?? 0,
149-
);
144+
final authorizationState = MobileScannerAuthorizationState.fromRawValue(
145+
await methodChannel.invokeMethod<int>('state') ?? 0,
146+
);
150147

151148
switch (authorizationState) {
152149
// Authorization was already granted, no need to request it again.
@@ -156,7 +153,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
156153
// So if the permission was denied, request it again.
157154
case MobileScannerAuthorizationState.denied:
158155
case MobileScannerAuthorizationState.undetermined:
159-
final bool permissionGranted =
156+
final permissionGranted =
160157
await methodChannel.invokeMethod<bool>('request') ?? false;
161158

162159
if (!permissionGranted) {
@@ -209,17 +206,19 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
209206
List<BarcodeFormat> formats = const <BarcodeFormat>[],
210207
}) async {
211208
try {
212-
final Map<Object?, Object?>? result = await methodChannel
213-
.invokeMapMethod<Object?, Object?>('analyzeImage', {
214-
'filePath': path,
215-
'formats':
216-
formats.isEmpty
217-
? null
218-
: [
219-
for (final BarcodeFormat format in formats)
220-
if (format != BarcodeFormat.unknown) format.rawValue,
221-
],
222-
});
209+
final result = await methodChannel.invokeMapMethod<Object?, Object?>(
210+
'analyzeImage',
211+
{
212+
'filePath': path,
213+
'formats':
214+
formats.isEmpty
215+
? null
216+
: [
217+
for (final BarcodeFormat format in formats)
218+
if (format != BarcodeFormat.unknown) format.rawValue,
219+
],
220+
},
221+
);
223222

224223
return _parseBarcode(result);
225224
} on PlatformException catch (error) {
@@ -282,7 +281,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
282281
throw UnimplementedError('setFocusPoint() has not been implemented.');
283282
}
284283

285-
final Map<String, Object?> params = <String, Object?>{
284+
final params = <String, Object?>{
286285
'dx': position.dx,
287286
'dy': position.dy,
288287
};
@@ -330,7 +329,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
330329
);
331330
}
332331

333-
final int? textureId = startResult['textureId'] as int?;
332+
final textureId = startResult['textureId'] as int?;
334333

335334
if (textureId == null) {
336335
throw const MobileScannerException(
@@ -341,7 +340,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
341340
);
342341
}
343342

344-
final CameraFacing cameraDirection = CameraFacing.fromRawValue(
343+
final cameraDirection = CameraFacing.fromRawValue(
345344
startResult['cameraDirection'] as int?,
346345
);
347346

@@ -364,8 +363,8 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
364363
initialDeviceOrientation = orientation.parseDeviceOrientation();
365364
}
366365

367-
final int? numberOfCameras = startResult['numberOfCameras'] as int?;
368-
final TorchState currentTorchState = TorchState.fromRawValue(
366+
final numberOfCameras = startResult['numberOfCameras'] as int?;
367+
final currentTorchState = TorchState.fromRawValue(
369368
startResult['currentTorchState'] as int? ?? -1,
370369
);
371370

lib/src/method_channel/rotated_preview.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class RotatedPreview extends StatefulWidget {
2727
required double sensorOrientationDegrees,
2828
Key? key,
2929
}) {
30-
final int facingSignForDirection = switch (cameraFacingDirection) {
30+
final facingSignForDirection = switch (cameraFacingDirection) {
3131
CameraFacing.front => 1,
3232
CameraFacing.back => -1,
3333
CameraFacing.unknown => 1,
@@ -101,7 +101,7 @@ final class _RotatedPreviewState extends State<RotatedPreview> {
101101
required double sensorOrientationDegrees,
102102
required int sign,
103103
}) {
104-
final double deviceOrientationDegrees = switch (orientation) {
104+
final deviceOrientationDegrees = switch (orientation) {
105105
DeviceOrientation.portraitUp => 0,
106106
DeviceOrientation.landscapeRight => 90,
107107
DeviceOrientation.portraitDown => 180,
@@ -110,7 +110,7 @@ final class _RotatedPreviewState extends State<RotatedPreview> {
110110

111111
// Rotate the camera preview according to
112112
// https://developer.android.com/media/camera/camera2/camera-preview#orientation_calculation.
113-
double rotationDegrees =
113+
var rotationDegrees =
114114
(sensorOrientationDegrees - deviceOrientationDegrees * sign + 360) %
115115
360;
116116

@@ -127,7 +127,7 @@ final class _RotatedPreviewState extends State<RotatedPreview> {
127127

128128
@override
129129
Widget build(BuildContext context) {
130-
final double rotationDegrees = _computeRotationDegrees(
130+
final rotationDegrees = _computeRotationDegrees(
131131
deviceOrientation,
132132
sensorOrientationDegrees: widget.sensorOrientationDegrees,
133133
sign: widget.facingSign,

lib/src/mobile_scanner.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class _MobileScannerState extends State<MobileScanner>
183183
return;
184184
}
185185

186-
final Rect newScanWindow = calculateScanWindowRelativeToTextureInPercentage(
186+
final newScanWindow = calculateScanWindowRelativeToTextureInPercentage(
187187
widget.fit,
188188
widget.scanWindow!,
189189
textureSize: scannerState.size,
@@ -215,8 +215,8 @@ class _MobileScannerState extends State<MobileScanner>
215215
return;
216216
}
217217

218-
final double dx = (newScanWindow.width - scanWindow!.width).abs();
219-
final double dy = (newScanWindow.height - scanWindow!.height).abs();
218+
final dx = (newScanWindow.width - scanWindow!.width).abs();
219+
final dy = (newScanWindow.height - scanWindow!.height).abs();
220220

221221
// The new scan window has changed enough, allow updating the scan window.
222222
if (dx >= widget.scanWindowUpdateThreshold ||
@@ -238,7 +238,7 @@ class _MobileScannerState extends State<MobileScanner>
238238
return widget.placeholderBuilder?.call(context) ?? defaultPlaceholder;
239239
}
240240

241-
final MobileScannerException? error = value.error;
241+
final error = value.error;
242242
if (error != null) {
243243
final Widget defaultError = ScannerErrorWidget(error: error);
244244

@@ -249,7 +249,7 @@ class _MobileScannerState extends State<MobileScanner>
249249
builder: (context, constraints) {
250250
_maybeUpdateScanWindow(value, constraints);
251251

252-
final Widget? overlay = widget.overlayBuilder?.call(
252+
final overlay = widget.overlayBuilder?.call(
253253
context,
254254
constraints,
255255
);
@@ -269,11 +269,9 @@ class _MobileScannerState extends State<MobileScanner>
269269
return GestureDetector(
270270
child: scannerWidget,
271271
onTapUp: (details) async {
272-
final Size size = MediaQuery.sizeOf(context);
273-
final double relativeX =
274-
details.globalPosition.dx / size.width;
275-
final double relativeY =
276-
details.globalPosition.dy / size.height;
272+
final size = MediaQuery.sizeOf(context);
273+
final relativeX = details.globalPosition.dx / size.width;
274+
final relativeY = details.globalPosition.dy / size.height;
277275

278276
await controller.setFocusPoint(
279277
Offset(relativeX, relativeY),

lib/src/mobile_scanner_controller.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:mobile_scanner/src/enums/torch_state.dart';
1616
import 'package:mobile_scanner/src/method_channel/mobile_scanner_method_channel.dart';
1717
import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
1818
import 'package:mobile_scanner/src/mobile_scanner_platform_interface.dart';
19-
import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart';
2019
import 'package:mobile_scanner/src/objects/barcode_capture.dart';
2120
import 'package:mobile_scanner/src/objects/mobile_scanner_state.dart';
2221
import 'package:mobile_scanner/src/objects/start_options.dart';
@@ -242,7 +241,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
242241

243242
_disposeListeners();
244243

245-
final TorchState oldTorchState = value.torchState;
244+
final oldTorchState = value.torchState;
246245

247246
// After the camera stopped, set the torch state to off,
248247
// as the torch state callback is never called when the camera is stopped.
@@ -319,7 +318,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
319318
return;
320319
}
321320

322-
final double clampedZoomScale = zoomScale.clamp(0.0, 1.0);
321+
final clampedZoomScale = zoomScale.clamp(0.0, 1.0);
323322

324323
// Update the zoom scale state to the new state.
325324
// When the platform has updated the zoom scale,
@@ -339,7 +338,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
339338
return;
340339
}
341340

342-
final Offset clampedPosition = Offset(
341+
final clampedPosition = Offset(
343342
position.dx.clamp(0, 1),
344343
position.dy.clamp(0, 1),
345344
);
@@ -426,7 +425,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
426425
value = value.copyWith(isStarting: true);
427426
}
428427

429-
final StartOptions options = StartOptions(
428+
final options = StartOptions(
430429
cameraDirection: cameraDirection ?? facing,
431430
cameraResolution: cameraResolution,
432431
detectionSpeed: detectionSpeed,
@@ -442,8 +441,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
442441
try {
443442
_setupListeners();
444443

445-
final MobileScannerViewAttributes viewAttributes =
446-
await MobileScannerPlatform.instance.start(options);
444+
final viewAttributes = await MobileScannerPlatform.instance.start(
445+
options,
446+
);
447447

448448
if (!_isDisposed) {
449449
value = value.copyWith(
@@ -508,8 +508,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
508508
Future<void> switchCamera() async {
509509
_throwIfNotInitialized();
510510

511-
final int? availableCameras = value.availableCameras;
512-
final CameraFacing cameraDirection = value.cameraDirection;
511+
final availableCameras = value.availableCameras;
512+
final cameraDirection = value.cameraDirection;
513513

514514
// Do nothing if the amount of cameras is less than 2 cameras.
515515
// If the the current platform does not provide the amount of cameras,
@@ -552,7 +552,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
552552
return;
553553
}
554554

555-
final TorchState torchState = value.torchState;
555+
final torchState = value.torchState;
556556

557557
if (torchState == TorchState.unavailable) {
558558
return;

lib/src/objects/address.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Address {
1010

1111
/// Creates a new [Address] instance from a map.
1212
factory Address.fromNative(Map<Object?, Object?> data) {
13-
final List<Object?>? addressLines = data['addressLines'] as List<Object?>?;
14-
final AddressType type = AddressType.fromRawValue(
13+
final addressLines = data['addressLines'] as List<Object?>?;
14+
final type = AddressType.fromRawValue(
1515
data['type'] as int? ?? 0,
1616
);
1717

lib/src/objects/barcode.dart

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,20 @@ class Barcode {
4040

4141
/// Creates a new [Barcode] instance from the given [data].
4242
factory Barcode.fromNative(Map<Object?, Object?> data) {
43-
final Map<Object?, Object?>? calendarEvent =
44-
data['calendarEvent'] as Map<Object?, Object?>?;
45-
final Map<Object?, Object?>? contactInfo =
46-
data['contactInfo'] as Map<Object?, Object?>?;
47-
final List<Object?>? corners = data['corners'] as List<Object?>?;
48-
final Map<Object?, Object?>? driverLicense =
49-
data['driverLicense'] as Map<Object?, Object?>?;
50-
final Map<Object?, Object?>? email =
51-
data['email'] as Map<Object?, Object?>?;
52-
final Map<Object?, Object?>? geoPoint =
53-
data['geoPoint'] as Map<Object?, Object?>?;
54-
final Map<Object?, Object?>? phone =
55-
data['phone'] as Map<Object?, Object?>?;
56-
final Map<Object?, Object?>? sms = data['sms'] as Map<Object?, Object?>?;
57-
final Map<Object?, Object?>? size = data['size'] as Map<Object?, Object?>?;
58-
final Map<Object?, Object?>? url = data['url'] as Map<Object?, Object?>?;
59-
final Map<Object?, Object?>? wifi = data['wifi'] as Map<Object?, Object?>?;
60-
61-
final double? barcodeWidth = size?['width'] as double?;
62-
final double? barcodeHeight = size?['height'] as double?;
43+
final calendarEvent = data['calendarEvent'] as Map<Object?, Object?>?;
44+
final contactInfo = data['contactInfo'] as Map<Object?, Object?>?;
45+
final corners = data['corners'] as List<Object?>?;
46+
final driverLicense = data['driverLicense'] as Map<Object?, Object?>?;
47+
final email = data['email'] as Map<Object?, Object?>?;
48+
final geoPoint = data['geoPoint'] as Map<Object?, Object?>?;
49+
final phone = data['phone'] as Map<Object?, Object?>?;
50+
final sms = data['sms'] as Map<Object?, Object?>?;
51+
final size = data['size'] as Map<Object?, Object?>?;
52+
final url = data['url'] as Map<Object?, Object?>?;
53+
final wifi = data['wifi'] as Map<Object?, Object?>?;
54+
55+
final barcodeWidth = size?['width'] as double?;
56+
final barcodeHeight = size?['height'] as double?;
6357

6458
return Barcode(
6559
calendarEvent:
@@ -75,8 +69,8 @@ class Barcode {
7569
corners.cast<Map<Object?, Object?>>().map((
7670
Map<Object?, Object?> e,
7771
) {
78-
final double x = e['x']! as double;
79-
final double y = e['y']! as double;
72+
final x = e['x']! as double;
73+
final y = e['y']! as double;
8074

8175
return Offset(x, y);
8276
}),
@@ -226,8 +220,8 @@ class Barcode {
226220
// The size and corners are in the same coordinate space,
227221
// which is the camera input.
228222
// If the barcode size is unknown, scale to 0,0.
229-
final double scaleX = size.width > 0 ? targetSize.width / size.width : 0;
230-
final double scaleY = size.height > 0 ? targetSize.height / size.height : 0;
223+
final scaleX = size.width > 0 ? targetSize.width / size.width : 0;
224+
final scaleY = size.height > 0 ? targetSize.height / size.height : 0;
231225

232226
return [
233227
for (final Offset offset in corners)

lib/src/objects/contact_info.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class ContactInfo {
1919

2020
/// Create a new [ContactInfo] instance from a map.
2121
factory ContactInfo.fromNative(Map<Object?, Object?> data) {
22-
final List<Object?>? addresses = data['addresses'] as List<Object?>?;
23-
final List<Object?>? emails = data['emails'] as List<Object?>?;
24-
final List<Object?>? phones = data['phones'] as List<Object?>?;
25-
final List<Object?>? urls = data['urls'] as List<Object?>?;
26-
final Map<Object?, Object?>? name = data['name'] as Map<Object?, Object?>?;
22+
final addresses = data['addresses'] as List<Object?>?;
23+
final emails = data['emails'] as List<Object?>?;
24+
final phones = data['phones'] as List<Object?>?;
25+
final urls = data['urls'] as List<Object?>?;
26+
final name = data['name'] as Map<Object?, Object?>?;
2727

2828
return ContactInfo(
2929
addresses:

0 commit comments

Comments
 (0)