Julian Steenbakker

style: flutter format

@@ -27,7 +27,8 @@ class _BarcodeScannerWithControllerState @@ -27,7 +27,8 @@ class _BarcodeScannerWithControllerState
27 Widget build(BuildContext context) { 27 Widget build(BuildContext context) {
28 return Scaffold( 28 return Scaffold(
29 backgroundColor: Colors.black, 29 backgroundColor: Colors.black,
30 - body: Builder(builder: (context) { 30 + body: Builder(
  31 + builder: (context) {
31 return Stack( 32 return Stack(
32 children: [ 33 children: [
33 MobileScanner( 34 MobileScanner(
@@ -42,7 +43,8 @@ class _BarcodeScannerWithControllerState @@ -42,7 +43,8 @@ class _BarcodeScannerWithControllerState
42 setState(() { 43 setState(() {
43 this.barcode = barcode.rawValue; 44 this.barcode = barcode.rawValue;
44 }); 45 });
45 - },), 46 + },
  47 + ),
46 Align( 48 Align(
47 alignment: Alignment.bottomCenter, 49 alignment: Alignment.bottomCenter,
48 child: Container( 50 child: Container(
@@ -58,16 +60,22 @@ class _BarcodeScannerWithControllerState @@ -58,16 +60,22 @@ class _BarcodeScannerWithControllerState
58 valueListenable: controller.torchState, 60 valueListenable: controller.torchState,
59 builder: (context, state, child) { 61 builder: (context, state, child) {
60 if (state == null) { 62 if (state == null) {
61 - return const Icon(Icons.flash_off,  
62 - color: Colors.grey,); 63 + return const Icon(
  64 + Icons.flash_off,
  65 + color: Colors.grey,
  66 + );
63 } 67 }
64 switch (state as TorchState) { 68 switch (state as TorchState) {
65 case TorchState.off: 69 case TorchState.off:
66 - return const Icon(Icons.flash_off,  
67 - color: Colors.grey,); 70 + return const Icon(
  71 + Icons.flash_off,
  72 + color: Colors.grey,
  73 + );
68 case TorchState.on: 74 case TorchState.on:
69 - return const Icon(Icons.flash_on,  
70 - color: Colors.yellow,); 75 + return const Icon(
  76 + Icons.flash_on,
  77 + color: Colors.yellow,
  78 + );
71 } 79 }
72 }, 80 },
73 ), 81 ),
@@ -81,11 +89,10 @@ class _BarcodeScannerWithControllerState @@ -81,11 +89,10 @@ class _BarcodeScannerWithControllerState
81 : const Icon(Icons.play_arrow), 89 : const Icon(Icons.play_arrow),
82 iconSize: 32.0, 90 iconSize: 32.0,
83 onPressed: () => setState(() { 91 onPressed: () => setState(() {
84 - isStarted  
85 - ? controller.stop()  
86 - : controller.start(); 92 + isStarted ? controller.stop() : controller.start();
87 isStarted = !isStarted; 93 isStarted = !isStarted;
88 - }),), 94 + }),
  95 + ),
89 Center( 96 Center(
90 child: SizedBox( 97 child: SizedBox(
91 width: MediaQuery.of(context).size.width - 200, 98 width: MediaQuery.of(context).size.width - 200,
@@ -129,22 +136,25 @@ class _BarcodeScannerWithControllerState @@ -129,22 +136,25 @@ class _BarcodeScannerWithControllerState
129 final ImagePicker _picker = ImagePicker(); 136 final ImagePicker _picker = ImagePicker();
130 // Pick an image 137 // Pick an image
131 final XFile? image = await _picker.pickImage( 138 final XFile? image = await _picker.pickImage(
132 - source: ImageSource.gallery,); 139 + source: ImageSource.gallery,
  140 + );
133 if (image != null) { 141 if (image != null) {
134 if (await controller.analyzeImage(image.path)) { 142 if (await controller.analyzeImage(image.path)) {
135 if (!mounted) return; 143 if (!mounted) return;
136 - ScaffoldMessenger.of(context)  
137 - .showSnackBar(const SnackBar( 144 + ScaffoldMessenger.of(context).showSnackBar(
  145 + const SnackBar(
138 content: Text('Barcode found!'), 146 content: Text('Barcode found!'),
139 backgroundColor: Colors.green, 147 backgroundColor: Colors.green,
140 - ),); 148 + ),
  149 + );
141 } else { 150 } else {
142 if (!mounted) return; 151 if (!mounted) return;
143 - ScaffoldMessenger.of(context)  
144 - .showSnackBar(const SnackBar( 152 + ScaffoldMessenger.of(context).showSnackBar(
  153 + const SnackBar(
145 content: Text('No barcode found!'), 154 content: Text('No barcode found!'),
146 backgroundColor: Colors.red, 155 backgroundColor: Colors.red,
147 - ),); 156 + ),
  157 + );
148 } 158 }
149 } 159 }
150 }, 160 },
@@ -155,7 +165,8 @@ class _BarcodeScannerWithControllerState @@ -155,7 +165,8 @@ class _BarcodeScannerWithControllerState
155 ), 165 ),
156 ], 166 ],
157 ); 167 );
158 - },), 168 + },
  169 + ),
159 ); 170 );
160 } 171 }
161 } 172 }
@@ -18,7 +18,8 @@ class _BarcodeScannerWithoutControllerState @@ -18,7 +18,8 @@ class _BarcodeScannerWithoutControllerState
18 Widget build(BuildContext context) { 18 Widget build(BuildContext context) {
19 return Scaffold( 19 return Scaffold(
20 backgroundColor: Colors.black, 20 backgroundColor: Colors.black,
21 - body: Builder(builder: (context) { 21 + body: Builder(
  22 + builder: (context) {
22 return Stack( 23 return Stack(
23 children: [ 24 children: [
24 MobileScanner( 25 MobileScanner(
@@ -28,7 +29,8 @@ class _BarcodeScannerWithoutControllerState @@ -28,7 +29,8 @@ class _BarcodeScannerWithoutControllerState
28 setState(() { 29 setState(() {
29 this.barcode = barcode.rawValue; 30 this.barcode = barcode.rawValue;
30 }); 31 });
31 - },), 32 + },
  33 + ),
32 Align( 34 Align(
33 alignment: Alignment.bottomCenter, 35 alignment: Alignment.bottomCenter,
34 child: Container( 36 child: Container(
@@ -60,7 +62,8 @@ class _BarcodeScannerWithoutControllerState @@ -60,7 +62,8 @@ class _BarcodeScannerWithoutControllerState
60 ), 62 ),
61 ], 63 ],
62 ); 64 );
63 - },), 65 + },
  66 + ),
64 ); 67 );
65 } 68 }
66 } 69 }
@@ -19,17 +19,22 @@ class MyHome extends StatelessWidget { @@ -19,17 +19,22 @@ class MyHome extends StatelessWidget {
19 children: [ 19 children: [
20 ElevatedButton( 20 ElevatedButton(
21 onPressed: () { 21 onPressed: () {
22 - Navigator.of(context).push(MaterialPageRoute( 22 + Navigator.of(context).push(
  23 + MaterialPageRoute(
23 builder: (context) => const BarcodeScannerWithController(), 24 builder: (context) => const BarcodeScannerWithController(),
24 - ),); 25 + ),
  26 + );
25 }, 27 },
26 child: const Text('MobileScanner with Controller'), 28 child: const Text('MobileScanner with Controller'),
27 ), 29 ),
28 ElevatedButton( 30 ElevatedButton(
29 onPressed: () { 31 onPressed: () {
30 - Navigator.of(context).push(MaterialPageRoute(  
31 - builder: (context) => const BarcodeScannerWithoutController(),  
32 - ),); 32 + Navigator.of(context).push(
  33 + MaterialPageRoute(
  34 + builder: (context) =>
  35 + const BarcodeScannerWithoutController(),
  36 + ),
  37 + );
33 }, 38 },
34 child: const Text('MobileScanner without Controller'), 39 child: const Text('MobileScanner without Controller'),
35 ), 40 ),
@@ -16,11 +16,13 @@ class MobileScannerWebPlugin { @@ -16,11 +16,13 @@ class MobileScannerWebPlugin {
16 final PluginEventChannel event = PluginEventChannel( 16 final PluginEventChannel event = PluginEventChannel(
17 'dev.steenbakker.mobile_scanner/scanner/event', 17 'dev.steenbakker.mobile_scanner/scanner/event',
18 const StandardMethodCodec(), 18 const StandardMethodCodec(),
19 - registrar,); 19 + registrar,
  20 + );
20 final MethodChannel channel = MethodChannel( 21 final MethodChannel channel = MethodChannel(
21 'dev.steenbakker.mobile_scanner/scanner/method', 22 'dev.steenbakker.mobile_scanner/scanner/method',
22 const StandardMethodCodec(), 23 const StandardMethodCodec(),
23 - registrar,); 24 + registrar,
  25 + );
24 final MobileScannerWebPlugin instance = MobileScannerWebPlugin(); 26 final MobileScannerWebPlugin instance = MobileScannerWebPlugin();
25 WidgetsFlutterBinding.ensureInitialized(); 27 WidgetsFlutterBinding.ensureInitialized();
26 28
@@ -59,7 +61,8 @@ class MobileScannerWebPlugin { @@ -59,7 +61,8 @@ class MobileScannerWebPlugin {
59 throw PlatformException( 61 throw PlatformException(
60 code: 'Unimplemented', 62 code: 'Unimplemented',
61 details: "The mobile_scanner plugin for web doesn't implement " 63 details: "The mobile_scanner plugin for web doesn't implement "
62 - "the method '${call.method}'",); 64 + "the method '${call.method}'",
  65 + );
63 } 66 }
64 } 67 }
65 68
@@ -90,7 +93,8 @@ class MobileScannerWebPlugin { @@ -90,7 +93,8 @@ class MobileScannerWebPlugin {
90 viewID, 93 viewID,
91 (int id) => vidDiv 94 (int id) => vidDiv
92 ..style.width = '100%' 95 ..style.width = '100%'
93 - ..style.height = '100%',); 96 + ..style.height = '100%',
  97 + );
94 98
95 // Check if stream is running 99 // Check if stream is running
96 if (_localStream != null) { 100 if (_localStream != null) {
@@ -109,7 +113,8 @@ class MobileScannerWebPlugin { @@ -109,7 +113,8 @@ class MobileScannerWebPlugin {
109 final constraints = { 113 final constraints = {
110 'video': VideoOptions( 114 'video': VideoOptions(
111 facingMode: 115 facingMode:
112 - cameraFacing == CameraFacing.front ? 'user' : 'environment',) 116 + cameraFacing == CameraFacing.front ? 'user' : 'environment',
  117 + )
113 }; 118 };
114 119
115 _localStream = 120 _localStream =
@@ -28,13 +28,13 @@ class MobileScanner extends StatefulWidget { @@ -28,13 +28,13 @@ class MobileScanner extends StatefulWidget {
28 final bool allowDuplicates; 28 final bool allowDuplicates;
29 29
30 /// Create a [MobileScanner] with a [controller], the [controller] must has been initialized. 30 /// Create a [MobileScanner] with a [controller], the [controller] must has been initialized.
31 - const MobileScanner(  
32 - {Key? key, 31 + const MobileScanner({
  32 + Key? key,
33 this.onDetect, 33 this.onDetect,
34 this.controller, 34 this.controller,
35 this.fit = BoxFit.cover, 35 this.fit = BoxFit.cover,
36 - this.allowDuplicates = false, })  
37 - : super(key: key); 36 + this.allowDuplicates = false,
  37 + }) : super(key: key);
38 38
39 @override 39 @override
40 State<MobileScanner> createState() => _MobileScannerState(); 40 State<MobileScanner> createState() => _MobileScannerState();
@@ -69,7 +69,8 @@ class _MobileScannerState extends State<MobileScanner> @@ -69,7 +69,8 @@ class _MobileScannerState extends State<MobileScanner>
69 69
70 @override 70 @override
71 Widget build(BuildContext context) { 71 Widget build(BuildContext context) {
72 - return LayoutBuilder(builder: (context, BoxConstraints constraints) { 72 + return LayoutBuilder(
  73 + builder: (context, BoxConstraints constraints) {
73 return ValueListenableBuilder( 74 return ValueListenableBuilder(
74 valueListenable: controller.args, 75 valueListenable: controller.args,
75 builder: (context, value, child) { 76 builder: (context, value, child) {
@@ -104,8 +105,10 @@ class _MobileScannerState extends State<MobileScanner> @@ -104,8 +105,10 @@ class _MobileScannerState extends State<MobileScanner>
104 ), 105 ),
105 ); 106 );
106 } 107 }
107 - },);  
108 - },); 108 + },
  109 + );
  110 + },
  111 + );
109 } 112 }
110 113
111 @override 114 @override
@@ -13,6 +13,10 @@ class MobileScannerArguments { @@ -13,6 +13,10 @@ class MobileScannerArguments {
13 final String? webId; 13 final String? webId;
14 14
15 /// Create a [MobileScannerArguments]. 15 /// Create a [MobileScannerArguments].
16 - MobileScannerArguments(  
17 - {this.textureId, required this.size, required this.hasTorch, this.webId, }); 16 + MobileScannerArguments({
  17 + this.textureId,
  18 + required this.size,
  19 + required this.hasTorch,
  20 + this.webId,
  21 + });
18 } 22 }
@@ -55,11 +55,12 @@ class MobileScannerController { @@ -55,11 +55,12 @@ class MobileScannerController {
55 55
56 Stream<Barcode> get barcodes => barcodesController.stream; 56 Stream<Barcode> get barcodes => barcodesController.stream;
57 57
58 - MobileScannerController(  
59 - {this.facing = CameraFacing.back, 58 + MobileScannerController({
  59 + this.facing = CameraFacing.back,
60 this.ratio, 60 this.ratio,
61 this.torchEnabled, 61 this.torchEnabled,
62 - this.formats, }) { 62 + this.formats,
  63 + }) {
63 // In case a new instance is created before calling dispose() 64 // In case a new instance is created before calling dispose()
64 if (_controllerHashcode != null) { 65 if (_controllerHashcode != null) {
65 stop(); 66 stop();
@@ -95,7 +96,11 @@ class MobileScannerController { @@ -95,7 +96,11 @@ class MobileScannerController {
95 barcodesController.add(barcode); 96 barcodesController.add(barcode);
96 break; 97 break;
97 case 'barcodeMac': 98 case 'barcodeMac':
98 - barcodesController.add(Barcode(rawValue: (data as Map<String, dynamic>)['payload'] as String)); 99 + barcodesController.add(
  100 + Barcode(
  101 + rawValue: (data as Map<String, dynamic>)['payload'] as String,
  102 + ),
  103 + );
99 break; 104 break;
100 case 'barcodeWeb': 105 case 'barcodeWeb':
101 barcodesController.add(Barcode(rawValue: data as String)); 106 barcodesController.add(Barcode(rawValue: data as String));
@@ -128,11 +133,12 @@ class MobileScannerController { @@ -128,11 +133,12 @@ class MobileScannerController {
128 133
129 // Check authorization status 134 // Check authorization status
130 if (!kIsWeb) { 135 if (!kIsWeb) {
131 - MobileScannerState state =  
132 - MobileScannerState.values[await methodChannel.invokeMethod('state') as int]; 136 + MobileScannerState state = MobileScannerState
  137 + .values[await methodChannel.invokeMethod('state') as int];
133 switch (state) { 138 switch (state) {
134 case MobileScannerState.undetermined: 139 case MobileScannerState.undetermined:
135 - final bool result = await methodChannel.invokeMethod('request') as bool; 140 + final bool result =
  141 + await methodChannel.invokeMethod('request') as bool;
136 state = result 142 state = result
137 ? MobileScannerState.authorized 143 ? MobileScannerState.authorized
138 : MobileScannerState.denied; 144 : MobileScannerState.denied;
@@ -165,7 +171,9 @@ class MobileScannerController { @@ -165,7 +171,9 @@ class MobileScannerController {
165 Map<String, dynamic>? startResult = {}; 171 Map<String, dynamic>? startResult = {};
166 try { 172 try {
167 startResult = await methodChannel.invokeMapMethod<String, dynamic>( 173 startResult = await methodChannel.invokeMapMethod<String, dynamic>(
168 - 'start', arguments,); 174 + 'start',
  175 + arguments,
  176 + );
169 } on PlatformException catch (error) { 177 } on PlatformException catch (error) {
170 debugPrint('${error.code}: ${error.message}'); 178 debugPrint('${error.code}: ${error.message}');
171 isStarting = false; 179 isStarting = false;
@@ -183,13 +191,18 @@ class MobileScannerController { @@ -183,13 +191,18 @@ class MobileScannerController {
183 if (kIsWeb) { 191 if (kIsWeb) {
184 args.value = MobileScannerArguments( 192 args.value = MobileScannerArguments(
185 webId: startResult['ViewID'] as String?, 193 webId: startResult['ViewID'] as String?,
186 - size: Size(startResult['videoWidth'] as double, startResult['videoHeight'] as double),  
187 - hasTorch: hasTorch,); 194 + size: Size(
  195 + startResult['videoWidth'] as double,
  196 + startResult['videoHeight'] as double,
  197 + ),
  198 + hasTorch: hasTorch,
  199 + );
188 } else { 200 } else {
189 args.value = MobileScannerArguments( 201 args.value = MobileScannerArguments(
190 textureId: startResult['textureId'] as int, 202 textureId: startResult['textureId'] as int,
191 size: toSize(startResult['size'] as Map<String, double>), 203 size: toSize(startResult['size'] as Map<String, double>),
192 - hasTorch: hasTorch,); 204 + hasTorch: hasTorch,
  205 + );
193 } 206 }
194 207
195 isStarting = false; 208 isStarting = false;
@@ -232,7 +245,8 @@ class MobileScannerController { @@ -232,7 +245,8 @@ class MobileScannerController {
232 await methodChannel.invokeMethod('stop'); 245 await methodChannel.invokeMethod('stop');
233 } on PlatformException catch (error) { 246 } on PlatformException catch (error) {
234 debugPrint( 247 debugPrint(
235 - '${error.code}: camera is stopped! Please start before switching camera.',); 248 + '${error.code}: camera is stopped! Please start before switching camera.',
  249 + );
236 return; 250 return;
237 } 251 }
238 facing = 252 facing =
@@ -63,8 +63,8 @@ class Barcode { @@ -63,8 +63,8 @@ class Barcode {
63 /// Gets parsed WiFi AP details. 63 /// Gets parsed WiFi AP details.
64 final WiFi? wifi; 64 final WiFi? wifi;
65 65
66 - Barcode(  
67 - {this.corners, 66 + Barcode({
  67 + this.corners,
68 this.format = BarcodeFormat.ean13, 68 this.format = BarcodeFormat.ean13,
69 this.rawBytes, 69 this.rawBytes,
70 this.type = BarcodeType.text, 70 this.type = BarcodeType.text,
@@ -77,7 +77,8 @@ class Barcode { @@ -77,7 +77,8 @@ class Barcode {
77 this.sms, 77 this.sms,
78 this.url, 78 this.url,
79 this.wifi, 79 this.wifi,
80 - required this.rawValue, }); 80 + required this.rawValue,
  81 + });
81 82
82 /// Create a [Barcode] from native data. 83 /// Create a [Barcode] from native data.
83 Barcode.fromNative(Map<String, dynamic> data) 84 Barcode.fromNative(Map<String, dynamic> data)
@@ -86,7 +87,8 @@ class Barcode { @@ -86,7 +87,8 @@ class Barcode {
86 rawBytes = data['rawBytes'] as Uint8List?, 87 rawBytes = data['rawBytes'] as Uint8List?,
87 rawValue = data['rawValue'] as String?, 88 rawValue = data['rawValue'] as String?,
88 type = BarcodeType.values[data['type'] as int], 89 type = BarcodeType.values[data['type'] as int],
89 - calendarEvent = toCalendarEvent(data['calendarEvent'] as Map<String, String?>?), 90 + calendarEvent =
  91 + toCalendarEvent(data['calendarEvent'] as Map<String, String?>?),
90 contactInfo = toContactInfo(data['contactInfo'] as Map?), 92 contactInfo = toContactInfo(data['contactInfo'] as Map?),
91 driverLicense = toDriverLicense(data['driverLicense'] as Map?), 93 driverLicense = toDriverLicense(data['driverLicense'] as Map?),
92 email = toEmail(data['email'] as Map?), 94 email = toEmail(data['email'] as Map?),
@@ -185,13 +187,16 @@ class ContactInfo { @@ -185,13 +187,16 @@ class ContactInfo {
185 /// Create a [ContactInfo] from native data. 187 /// Create a [ContactInfo] from native data.
186 ContactInfo.fromNative(Map<dynamic, dynamic> data) 188 ContactInfo.fromNative(Map<dynamic, dynamic> data)
187 : addresses = List.unmodifiable( 189 : addresses = List.unmodifiable(
188 - (data['addresses'] as List<Map>).map((e) => Address.fromNative(e)),),  
189 - emails =  
190 - List.unmodifiable((data['emails'] as List<Map>).map((e) => Email.fromNative(e))), 190 + (data['addresses'] as List<Map>).map((e) => Address.fromNative(e)),
  191 + ),
  192 + emails = List.unmodifiable(
  193 + (data['emails'] as List<Map>).map((e) => Email.fromNative(e)),
  194 + ),
191 name = toName(data['name'] as Map?), 195 name = toName(data['name'] as Map?),
192 organization = data['organization'] as String?, 196 organization = data['organization'] as String?,
193 - phones =  
194 - List.unmodifiable((data['phones'] as List<Map>).map((e) => Phone.fromNative(e))), 197 + phones = List.unmodifiable(
  198 + (data['phones'] as List<Map>).map((e) => Phone.fromNative(e)),
  199 + ),
195 title = data['title'] as String?, 200 title = data['title'] as String?,
196 urls = List.unmodifiable(data['urls'] as List); 201 urls = List.unmodifiable(data['urls'] as List);
197 } 202 }
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 import 'package:mobile_scanner/mobile_scanner.dart'; 2 import 'package:mobile_scanner/mobile_scanner.dart';
3 3
4 -  
5 Size toSize(Map<dynamic, double> data) { 4 Size toSize(Map<dynamic, double> data) {
6 final width = data['width']!; 5 final width = data['width']!;
7 final height = data['height']!; 6 final height = data['height']!;
@@ -10,7 +9,9 @@ Size toSize(Map<dynamic, double> data) { @@ -10,7 +9,9 @@ Size toSize(Map<dynamic, double> data) {
10 9
11 List<Offset>? toCorners(List<Map>? data) { 10 List<Offset>? toCorners(List<Map>? data) {
12 if (data != null) { 11 if (data != null) {
13 - return List.unmodifiable(data.map((e) => Offset(e['x'] as double, e['y'] as double))); 12 + return List.unmodifiable(
  13 + data.map((e) => Offset(e['x'] as double, e['y'] as double)),
  14 + );
14 } else { 15 } else {
15 return null; 16 return null;
16 } 17 }
@@ -25,8 +25,12 @@ class VideoOptions { @@ -25,8 +25,12 @@ class VideoOptions {
25 external Map get width; 25 external Map get width;
26 external Map get height; 26 external Map get height;
27 27
28 - external factory VideoOptions(  
29 - {String? facingMode, DeviceIdOptions? deviceId, Map? width, Map? height, }); 28 + external factory VideoOptions({
  29 + String? facingMode,
  30 + DeviceIdOptions? deviceId,
  31 + Map? width,
  32 + Map? height,
  33 + });
30 } 34 }
31 35
32 @JS() 36 @JS()