Skip to content

Commit 19689a3

Browse files
authored
Merge pull request #16 from jhoogstraat/linting
Add linting to Dart, Android and iOS
2 parents 21dec07 + 9296e61 commit 19689a3

20 files changed

+102
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flutter_lints/flutter.yaml

fast_barcode_scanner/android/src/main/kotlin/com/jhoogstraat/fast_barcode_scanner/FastBarcodeScannerPlugin.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.jhoogstraat.fast_barcode_scanner
22

33

4-
import androidx.annotation.NonNull;
4+
import androidx.annotation.NonNull
55
import io.flutter.embedding.android.FlutterActivity
66

7-
import io.flutter.embedding.engine.plugins.FlutterPlugin;
8-
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
7+
import io.flutter.embedding.engine.plugins.FlutterPlugin
8+
import io.flutter.embedding.engine.plugins.activity.ActivityAware
99
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
1010

1111
import io.flutter.plugin.common.MethodCall
@@ -14,7 +14,7 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
1414
import io.flutter.plugin.common.MethodChannel.Result
1515

1616
/** FastBarcodeScannerPlugin */
17-
public class FastBarcodeScannerPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
17+
class FastBarcodeScannerPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
1818
private lateinit var channel : MethodChannel
1919
private lateinit var reader: BarcodeReader
2020

@@ -52,6 +52,7 @@ public class FastBarcodeScannerPlugin: FlutterPlugin, MethodCallHandler, Activit
5252
}
5353

5454
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
55+
@Suppress("UNCHECKED_CAST")
5556
when (call.method) {
5657
"start" -> reader.start(call.arguments as HashMap<String, Any>, result)
5758
"stop" -> reader.stop(result)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flutter_lints/flutter.yaml

fast_barcode_scanner/example/ios/Podfile

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target 'Runner' do
3232
use_modular_headers!
3333

3434
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35+
pod 'SwiftLint'
3536
end
3637

3738
post_install do |installer|

fast_barcode_scanner/example/ios/Podfile.lock

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ PODS:
22
- fast_barcode_scanner (0.0.1):
33
- Flutter
44
- Flutter (1.0.0)
5+
- SwiftLint (0.43.1)
56

67
DEPENDENCIES:
78
- fast_barcode_scanner (from `.symlinks/plugins/fast_barcode_scanner/ios`)
89
- Flutter (from `Flutter`)
10+
- SwiftLint
11+
12+
SPEC REPOS:
13+
trunk:
14+
- SwiftLint
915

1016
EXTERNAL SOURCES:
1117
fast_barcode_scanner:
@@ -16,7 +22,8 @@ EXTERNAL SOURCES:
1622
SPEC CHECKSUMS:
1723
fast_barcode_scanner: 0df01447443e9f9c7a6859844d8c4719887100b4
1824
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
25+
SwiftLint: 99f82d07b837b942dd563c668de129a03fc3fb52
1926

20-
PODFILE CHECKSUM: fe0e1ee7f3d1f7d00b11b474b62dd62134535aea
27+
PODFILE CHECKSUM: 395641e259d365c89c7b492d0a7bb47b50dab597
2128

2229
COCOAPODS: 1.10.0

fast_barcode_scanner/example/ios/Runner.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
);
241241
runOnlyForDeploymentPostprocessing = 0;
242242
shellPath = /bin/sh;
243-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
243+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n";
244244
};
245245
A9CE08C8DCEDA09AA1BDB13E /* [CP] Check Pods Manifest.lock */ = {
246246
isa = PBXShellScriptBuildPhase;

fast_barcode_scanner/example/lib/detections_counter.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:fast_barcode_scanner_example/scanner_screen.dart';
33
import 'package:flutter/material.dart';
44

55
class DetectionsCounter extends StatefulWidget {
6+
const DetectionsCounter({Key? key}) : super(key: key);
7+
68
@override
79
_DetectionsCounterState createState() => _DetectionsCounterState();
810
}
@@ -25,7 +27,7 @@ class _DetectionsCounterState extends State<DetectionsCounter> {
2527
@override
2628
Widget build(BuildContext context) {
2729
return Container(
28-
decoration: BoxDecoration(
30+
decoration: const BoxDecoration(
2931
color: Colors.white,
3032
borderRadius: BorderRadius.all(Radius.circular(15)),
3133
),

fast_barcode_scanner/example/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import 'package:flutter/material.dart';
33
import 'scanner_screen.dart';
44

55
void main() {
6-
runApp(MaterialApp(home: ScannerScreen()));
6+
runApp(const MaterialApp(home: ScannerScreen()));
77
}

fast_barcode_scanner/example/lib/scanner_screen.dart

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'detections_counter.dart';
77
final codeStream = StreamController<Barcode>.broadcast();
88

99
class ScannerScreen extends StatefulWidget {
10+
const ScannerScreen({Key? key}) : super(key: key);
11+
1012
@override
1113
_ScannerScreenState createState() => _ScannerScreenState();
1214
}
@@ -43,7 +45,7 @@ class _ScannerScreenState extends State<ScannerScreen> {
4345
],
4446
),
4547
body: BarcodeCamera(
46-
types: [
48+
types: const [
4749
BarcodeType.ean8,
4850
BarcodeType.ean13,
4951
BarcodeType.code128,
@@ -55,20 +57,20 @@ class _ScannerScreenState extends State<ScannerScreen> {
5557
position: CameraPosition.back,
5658
onScan: (code) => codeStream.add(code),
5759
children: [
58-
MaterialPreviewOverlay(animateDetection: false),
59-
BlurPreviewOverlay(),
60+
const MaterialPreviewOverlay(animateDetection: false),
61+
const BlurPreviewOverlay(),
6062
Positioned(
6163
bottom: 50,
6264
left: 0,
6365
right: 0,
6466
child: Column(
6567
children: [
6668
ElevatedButton(
67-
child: Text("Resume"),
69+
child: const Text("Resume"),
6870
onPressed: () => CameraController.instance.resumeDetector(),
6971
),
70-
SizedBox(height: 20),
71-
DetectionsCounter()
72+
const SizedBox(height: 20),
73+
const DetectionsCounter()
7274
],
7375
),
7476
)

fast_barcode_scanner/example/pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ dependencies:
1212
fast_barcode_scanner:
1313
path: ../
1414

15+
dev_dependencies:
16+
flutter_lints: ^1.0.3
17+
1518
flutter:
1619
uses-material-design: true

fast_barcode_scanner/ios/Classes/BarcodeReader.swift

+16-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import Flutter
1212
let avMetadataObjectTypes: [String: AVMetadataObject.ObjectType] =
1313
[
1414
"aztec": .aztec,
15-
"code128":.code128,
15+
"code128": .code128,
1616
"code39": .code39,
1717
"code39mod43": .code39Mod43,
1818
"code93": .code93,
1919
"dataMatrix": .dataMatrix,
2020
"ean13": .ean13,
2121
"ean8": .ean8,
22-
"itf": .itf14,
22+
"itf": .itf14,
2323
"pdf417": .pdf417,
2424
"qr": .qr,
2525
"upcE": .upce,
@@ -94,7 +94,9 @@ class BarcodeReader: NSObject {
9494
var torchActiveBeforeStop = false
9595
var previewSize: CMVideoDimensions!
9696

97-
init(textureRegistry: FlutterTextureRegistry, arguments: StartArgs, codeCallback: @escaping ([String]) -> Void) throws {
97+
init(textureRegistry: FlutterTextureRegistry,
98+
arguments: StartArgs,
99+
codeCallback: @escaping ([String]) -> Void) throws {
98100
self.textureRegistry = textureRegistry
99101
self.codeCallback = codeCallback
100102
self.captureSession = AVCaptureSession()
@@ -125,7 +127,7 @@ class BarcodeReader: NSObject {
125127
captureSession.addOutput(metadataOutput)
126128

127129
dataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA]
128-
dataOutput.connection(with: .video)?.videoOrientation = .portrait // TODO: Get real interface orientation
130+
dataOutput.connection(with: .video)?.videoOrientation = .portrait
129131
dataOutput.alwaysDiscardsLateVideoFrames = true
130132
dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: .default))
131133

@@ -144,6 +146,7 @@ class BarcodeReader: NSObject {
144146
throw ReaderError.cameraNotSuitable(arguments.resolution, arguments.framerate)
145147
}
146148

149+
// swiftlint:disable:next force_try
147150
try! captureDevice.lockForConfiguration()
148151
captureDevice.activeFormat = optimalFormat
149152
captureDevice.activeVideoMinFrameDuration = optimalFormat.videoSupportedFrameRateRanges.first!.minFrameDuration
@@ -160,7 +163,8 @@ class BarcodeReader: NSObject {
160163
self.textureId = textureRegistry.register(self)
161164
}
162165

163-
if (torchActiveBeforeStop) {
166+
if torchActiveBeforeStop {
167+
// swiftlint:disable:next force_try
164168
try! captureDevice.lockForConfiguration()
165169
captureDevice.torchMode = .on
166170
captureDevice.unlockForConfiguration()
@@ -179,6 +183,7 @@ class BarcodeReader: NSObject {
179183
}
180184

181185
func toggleTorch() -> Bool {
186+
// swiftlint:disable:next force_try
182187
try! captureDevice.lockForConfiguration()
183188
captureDevice.torchMode = captureDevice.isTorchActive ? .off : .on
184189
captureDevice.unlockForConfiguration()
@@ -215,15 +220,19 @@ extension BarcodeReader: FlutterTexture {
215220

216221
extension BarcodeReader: AVCaptureVideoDataOutputSampleBufferDelegate {
217222
// runs on dispatch queue
218-
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
223+
func captureOutput(_ output: AVCaptureOutput,
224+
didOutput sampleBuffer: CMSampleBuffer,
225+
from connection: AVCaptureConnection) {
219226
pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
220227
textureRegistry.textureFrameAvailable(textureId)
221228
}
222229
}
223230

224231
extension BarcodeReader: AVCaptureMetadataOutputObjectsDelegate {
225232
// runs on dispatch queue
226-
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
233+
func metadataOutput(_ output: AVCaptureMetadataOutput,
234+
didOutput metadataObjects: [AVMetadataObject],
235+
from connection: AVCaptureConnection) {
227236
guard
228237
let metadata = metadataObjects.first,
229238
let readableCode = metadata as? AVMetadataMachineReadableCodeObject
@@ -246,4 +255,3 @@ extension FourCharCode {
246255
])
247256
}
248257
}
249-

fast_barcode_scanner/ios/Classes/FastBarcodeScannerPlugin.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct StartArgs {
1313
else {
1414
return nil
1515
}
16-
16+
1717
self.position = position
1818
self.framerate = framerate
1919
self.resolution = resolution
@@ -33,7 +33,7 @@ public class FastBarcodeScannerPlugin: NSObject, FlutterPlugin {
3333
let textureRegistry: FlutterTextureRegistry
3434
let channel: FlutterMethodChannel
3535

36-
var reader: BarcodeReader? = nil
36+
var reader: BarcodeReader?
3737

3838
init(channel: FlutterMethodChannel, textureRegistry: FlutterTextureRegistry) {
3939
self.textureRegistry = textureRegistry
@@ -86,17 +86,20 @@ public class FastBarcodeScannerPlugin: NSObject, FlutterPlugin {
8686
result([
8787
"surfaceWidth": reader!.previewSize.height,
8888
"surfaceHeight": reader!.previewSize.width,
89-
"surfaceOrientation": 0, //TODO: check on iPad
89+
"surfaceOrientation": 0,
9090
"textureId": reader!.textureId!
9191
])
9292

9393
} catch ReaderError.noInputDevice {
9494
result(FlutterError(code: "AV_NO_INPUT_DEVICE",
9595
message: "No input device found",
9696
details: "Are you using a simulator?"))
97-
} catch ReaderError.cameraNotSuitable(let res, let fps){
97+
} catch ReaderError.cameraNotSuitable(let res, let fps) {
9898
result(FlutterError(code: "CAMERA_NOT_SUITABLE",
99-
message: "The camera does not support the requested resolution (\(res)) and framerate (\(fps)) combination",
99+
message: """
100+
The camera does not support the requested resolution (\(res)) \
101+
and framerate (\(fps)) combination
102+
""",
100103
details: "try to lower your settings"))
101104
} catch ReaderError.unauthorized {
102105
result(FlutterError(code: "UNAUTHORIZED",
@@ -129,6 +132,3 @@ public class FastBarcodeScannerPlugin: NSObject, FlutterPlugin {
129132
result(nil)
130133
}
131134
}
132-
133-
134-

fast_barcode_scanner/lib/src/barcode_camera.dart

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter/rendering.dart';
88

9-
typedef Widget ErrorCallback(BuildContext context, Object? error);
9+
typedef ErrorCallback = Widget Function(BuildContext context, Object? error);
1010

11-
final ErrorCallback _defaultOnError = (BuildContext context, Object? error) {
11+
Widget _defaultOnError(BuildContext context, Object? error) {
1212
debugPrint("Error reading from camera: $error");
13-
return Center(child: Text("Error reading from camera..."));
14-
};
13+
return const Center(child: Text("Error reading from camera..."));
14+
}
1515

1616
/// The main class connecting the platform code to the UI.
1717
///
1818
/// This class is used in the widget tree and connects to the camera
1919
/// as soon as didChangeDependencies gets called.
2020
class BarcodeCamera extends StatefulWidget {
21-
BarcodeCamera(
22-
{Key? key,
23-
required this.types,
24-
this.mode = DetectionMode.pauseVideo,
25-
this.resolution = Resolution.hd720,
26-
this.framerate = Framerate.fps30,
27-
this.position = CameraPosition.back,
28-
this.onScan,
29-
this.children = const [],
30-
ErrorCallback? onError})
31-
: onError = onError ?? _defaultOnError,
21+
const BarcodeCamera({
22+
Key? key,
23+
required this.types,
24+
this.mode = DetectionMode.pauseVideo,
25+
this.resolution = Resolution.hd720,
26+
this.framerate = Framerate.fps30,
27+
this.position = CameraPosition.back,
28+
this.onScan,
29+
this.children = const [],
30+
ErrorCallback? onError,
31+
}) : onError = onError ?? _defaultOnError,
3232
super(key: key);
3333

3434
final List<BarcodeType> types;

0 commit comments

Comments
 (0)