Julian Steenbakker

style: flutter format

@@ -18,8 +18,10 @@ class _AnalyzeViewState extends State<AnalyzeView> @@ -18,8 +18,10 @@ class _AnalyzeViewState extends State<AnalyzeView>
18 with SingleTickerProviderStateMixin { 18 with SingleTickerProviderStateMixin {
19 String? barcode; 19 String? barcode;
20 20
21 - MobileScannerController controller = MobileScannerController(torchEnabled: true,  
22 - facing: CameraFacing.front,); 21 + MobileScannerController controller = MobileScannerController(
  22 + torchEnabled: true,
  23 + facing: CameraFacing.front,
  24 + );
23 25
24 @override 26 @override
25 Widget build(BuildContext context) { 27 Widget build(BuildContext context) {
@@ -30,7 +32,7 @@ class _AnalyzeViewState extends State<AnalyzeView> @@ -30,7 +32,7 @@ class _AnalyzeViewState extends State<AnalyzeView>
30 return Stack( 32 return Stack(
31 children: [ 33 children: [
32 MobileScanner( 34 MobileScanner(
33 - controller: controller, 35 + controller: controller,
34 fit: BoxFit.contain, 36 fit: BoxFit.contain,
35 // controller: MobileScannerController( 37 // controller: MobileScannerController(
36 // torchEnabled: true, 38 // torchEnabled: true,
@@ -55,20 +57,22 @@ class _AnalyzeViewState extends State<AnalyzeView> @@ -55,20 +57,22 @@ class _AnalyzeViewState extends State<AnalyzeView>
55 children: [ 57 children: [
56 IconButton( 58 IconButton(
57 color: Colors.white, 59 color: Colors.white,
58 - icon: ValueListenableBuilder(  
59 - valueListenable: controller.torchState,  
60 - builder: (context, state, child) {  
61 - switch (state as TorchState) {  
62 - case TorchState.off:  
63 - return const Icon(Icons.flash_off, color: Colors.grey);  
64 - case TorchState.on:  
65 - return const Icon(Icons.flash_on, color: Colors.yellow);  
66 - }  
67 - },  
68 - ),  
69 - iconSize: 32.0,  
70 - onPressed: () => controller.toggleTorch(), 60 + icon: ValueListenableBuilder(
  61 + valueListenable: controller.torchState,
  62 + builder: (context, state, child) {
  63 + switch (state as TorchState) {
  64 + case TorchState.off:
  65 + return const Icon(Icons.flash_off,
  66 + color: Colors.grey);
  67 + case TorchState.on:
  68 + return const Icon(Icons.flash_on,
  69 + color: Colors.yellow);
  70 + }
  71 + },
71 ), 72 ),
  73 + iconSize: 32.0,
  74 + onPressed: () => controller.toggleTorch(),
  75 + ),
72 Center( 76 Center(
73 child: SizedBox( 77 child: SizedBox(
74 width: MediaQuery.of(context).size.width - 120, 78 width: MediaQuery.of(context).size.width - 120,
@@ -30,40 +30,41 @@ class _AnalyzeViewState extends State<AnalyzeView> @@ -30,40 +30,41 @@ class _AnalyzeViewState extends State<AnalyzeView>
30 return Stack( 30 return Stack(
31 children: [ 31 children: [
32 MobileScanner( 32 MobileScanner(
33 - // fitScreen: false, 33 + // fitScreen: false,
34 // controller: cameraController, 34 // controller: cameraController,
35 onDetect: (barcode, args) { 35 onDetect: (barcode, args) {
36 - if (this.barcode != barcode.rawValue) {  
37 - this.barcode = barcode.rawValue;  
38 - if (barcode.corners != null) {  
39 - ScaffoldMessenger.of(context).showSnackBar(SnackBar(  
40 - content: Text('${barcode.rawValue}'),  
41 - duration: const Duration(milliseconds: 200),  
42 - animation: null,  
43 - ));  
44 - setState(() {  
45 - final List<Offset> points = [];  
46 - double factorWidth = args.size.width / 520;  
47 - // double factorHeight = wanted / args.size.height;  
48 - final size = MediaQuery.of(context).devicePixelRatio;  
49 - debugPrint('Size: ${barcode.corners}');  
50 - for (var point in barcode.corners!) {  
51 - final adjustedWith = point.dx ;  
52 - final adjustedHeight= point.dy ;  
53 - points.add(Offset(adjustedWith / size, adjustedHeight / size));  
54 - // points.add(Offset((point.dx ) / size,  
55 - // (point.dy) / size));  
56 - // final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;  
57 - // final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;  
58 - // points.add(Offset((point.dx + differenceWidth) / size,  
59 - // (point.dy + differenceHeight) / size));  
60 - }  
61 - this.points = points;  
62 - }); 36 + if (this.barcode != barcode.rawValue) {
  37 + this.barcode = barcode.rawValue;
  38 + if (barcode.corners != null) {
  39 + ScaffoldMessenger.of(context).showSnackBar(SnackBar(
  40 + content: Text('${barcode.rawValue}'),
  41 + duration: const Duration(milliseconds: 200),
  42 + animation: null,
  43 + ));
  44 + setState(() {
  45 + final List<Offset> points = [];
  46 + double factorWidth = args.size.width / 520;
  47 + // double factorHeight = wanted / args.size.height;
  48 + final size = MediaQuery.of(context).devicePixelRatio;
  49 + debugPrint('Size: ${barcode.corners}');
  50 + for (var point in barcode.corners!) {
  51 + final adjustedWith = point.dx;
  52 + final adjustedHeight = point.dy;
  53 + points.add(
  54 + Offset(adjustedWith / size, adjustedHeight / size));
  55 + // points.add(Offset((point.dx ) / size,
  56 + // (point.dy) / size));
  57 + // final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;
  58 + // final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;
  59 + // points.add(Offset((point.dx + differenceWidth) / size,
  60 + // (point.dy + differenceHeight) / size));
63 } 61 }
64 - }  
65 - // Default 640 x480  
66 - }), 62 + this.points = points;
  63 + });
  64 + }
  65 + }
  66 + // Default 640 x480
  67 + }),
67 CustomPaint( 68 CustomPaint(
68 painter: OpenPainter(points), 69 painter: OpenPainter(points),
69 ), 70 ),
@@ -2,4 +2,4 @@ library mobile_scanner; @@ -2,4 +2,4 @@ library mobile_scanner;
2 2
3 export 'src/mobile_scanner.dart'; 3 export 'src/mobile_scanner.dart';
4 export 'src/mobile_scanner_controller.dart'; 4 export 'src/mobile_scanner_controller.dart';
5 -export 'src/objects/barcode.dart';  
  5 +export 'src/objects/barcode.dart';
@@ -3,10 +3,7 @@ import 'package:mobile_scanner/mobile_scanner.dart'; @@ -3,10 +3,7 @@ import 'package:mobile_scanner/mobile_scanner.dart';
3 3
4 import 'mobile_scanner_arguments.dart'; 4 import 'mobile_scanner_arguments.dart';
5 5
6 -enum Ratio {  
7 - ratio_4_3,  
8 - ratio_16_9  
9 -} 6 +enum Ratio { ratio_4_3, ratio_16_9 }
10 7
11 /// A widget showing a live camera preview. 8 /// A widget showing a live camera preview.
12 class MobileScanner extends StatefulWidget { 9 class MobileScanner extends StatefulWidget {
@@ -18,7 +15,8 @@ class MobileScanner extends StatefulWidget { @@ -18,7 +15,8 @@ class MobileScanner extends StatefulWidget {
18 /// Create a [MobileScanner] with a [controller], the [controller] must has been initialized. 15 /// Create a [MobileScanner] with a [controller], the [controller] must has been initialized.
19 const MobileScanner( 16 const MobileScanner(
20 {Key? key, this.onDetect, this.controller, this.fit = BoxFit.cover}) 17 {Key? key, this.onDetect, this.controller, this.fit = BoxFit.cover})
21 - : assert((controller != null )), super(key: key); 18 + : assert((controller != null)),
  19 + super(key: key);
22 20
23 @override 21 @override
24 State<MobileScanner> createState() => _MobileScannerState(); 22 State<MobileScanner> createState() => _MobileScannerState();
@@ -91,4 +89,4 @@ class _MobileScannerState extends State<MobileScanner> @@ -91,4 +89,4 @@ class _MobileScannerState extends State<MobileScanner>
91 controller.dispose(); 89 controller.dispose();
92 super.dispose(); 90 super.dispose();
93 } 91 }
94 -}  
  92 +}
@@ -11,5 +11,6 @@ class MobileScannerArguments { @@ -11,5 +11,6 @@ class MobileScannerArguments {
11 final bool hasTorch; 11 final bool hasTorch;
12 12
13 /// Create a [MobileScannerArguments]. 13 /// Create a [MobileScannerArguments].
14 - MobileScannerArguments({required this.textureId,required this.size, required this.hasTorch}); 14 + MobileScannerArguments(
  15 + {required this.textureId, required this.size, required this.hasTorch});
15 } 16 }
@@ -38,7 +38,6 @@ class MobileScannerController { @@ -38,7 +38,6 @@ class MobileScannerController {
38 int? _controllerHashcode; 38 int? _controllerHashcode;
39 StreamSubscription? events; 39 StreamSubscription? events;
40 40
41 -  
42 final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null); 41 final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null);
43 final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off); 42 final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off);
44 late final ValueNotifier<CameraFacing> cameraFacingState; 43 late final ValueNotifier<CameraFacing> cameraFacingState;
@@ -107,7 +106,8 @@ class MobileScannerController { @@ -107,7 +106,8 @@ class MobileScannerController {
107 106
108 setAnalyzeMode(AnalyzeMode.barcode.index); 107 setAnalyzeMode(AnalyzeMode.barcode.index);
109 // Check authorization status 108 // Check authorization status
110 - MobileScannerState state = MobileScannerState.values[await methodChannel.invokeMethod('state')]; 109 + MobileScannerState state =
  110 + MobileScannerState.values[await methodChannel.invokeMethod('state')];
111 switch (state) { 111 switch (state) {
112 case MobileScannerState.undetermined: 112 case MobileScannerState.undetermined:
113 final bool result = await methodChannel.invokeMethod('request'); 113 final bool result = await methodChannel.invokeMethod('request');
@@ -129,13 +129,17 @@ class MobileScannerController { @@ -129,13 +129,17 @@ class MobileScannerController {
129 if (torchEnabled != null) arguments['torch'] = torchEnabled; 129 if (torchEnabled != null) arguments['torch'] = torchEnabled;
130 130
131 // Start the camera with arguments 131 // Start the camera with arguments
132 - final Map<String, dynamic>? startResult = await methodChannel.invokeMapMethod<String, dynamic>(  
133 - 'start', arguments); 132 + final Map<String, dynamic>? startResult = await methodChannel
  133 + .invokeMapMethod<String, dynamic>('start', arguments);
134 134
135 - if (startResult == null) throw PlatformException(code: 'INITIALIZATION ERROR'); 135 + if (startResult == null)
  136 + throw PlatformException(code: 'INITIALIZATION ERROR');
136 137
137 hasTorch = startResult['torchable']; 138 hasTorch = startResult['torchable'];
138 - args.value = MobileScannerArguments(textureId: startResult['textureId'], size: toSize(startResult['size']), hasTorch: hasTorch); 139 + args.value = MobileScannerArguments(
  140 + textureId: startResult['textureId'],
  141 + size: toSize(startResult['size']),
  142 + hasTorch: hasTorch);
139 } 143 }
140 144
141 Future<void> stop() async => await methodChannel.invokeMethod('stop'); 145 Future<void> stop() async => await methodChannel.invokeMethod('stop');
@@ -157,7 +161,8 @@ class MobileScannerController { @@ -157,7 +161,8 @@ class MobileScannerController {
157 Future<void> switchCamera() async { 161 Future<void> switchCamera() async {
158 ensure('switchCamera'); 162 ensure('switchCamera');
159 await stop(); 163 await stop();
160 - facing = facing == CameraFacing.back ? CameraFacing.front : CameraFacing.back; 164 + facing =
  165 + facing == CameraFacing.back ? CameraFacing.front : CameraFacing.back;
161 start(); 166 start();
162 } 167 }
163 168
@@ -16,5 +16,4 @@ void main() { @@ -16,5 +16,4 @@ void main() {
16 tearDown(() { 16 tearDown(() {
17 channel.setMockMethodCallHandler(null); 17 channel.setMockMethodCallHandler(null);
18 }); 18 });
19 -  
20 } 19 }