Julian Steenbakker

imp: apply lint

1 -include: package:flutter_lints/flutter.yaml  
2 -  
3 -linter:  
4 - rules:  
5 - unawaited_futures: true  
  1 +include: package:lint/analysis_options_package.yaml
1 -# This file configures the analyzer, which statically analyzes Dart code to  
2 -# check for errors, warnings, and lints.  
3 -#  
4 -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled  
5 -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be  
6 -# invoked from the command line by running `flutter analyze`.  
7 -  
8 -# The following line activates a set of recommended lints for Flutter apps,  
9 -# packages, and plugins designed to encourage good coding practices.  
10 -include: package:flutter_lints/flutter.yaml  
11 -  
12 -linter:  
13 - # The lint rules applied to this project can be customized in the  
14 - # section below to disable rules from the `package:flutter_lints/flutter.yaml`  
15 - # included above or to enable additional rules. A list of all available lints  
16 - # and their documentation is published at  
17 - # https://dart-lang.github.io/linter/lints/index.html.  
18 - #  
19 - # Instead of disabling a lint rule for the entire project in the  
20 - # section below, it can also be suppressed for a single line of code  
21 - # or a specific dart file by using the `// ignore: name_of_lint` and  
22 - # `// ignore_for_file: name_of_lint` syntax on the line or in the file  
23 - # producing the lint.  
24 - rules:  
25 - # avoid_print: false # Uncomment to disable the `avoid_print` rule  
26 - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule  
27 -  
28 -# Additional information about this file can be found at  
29 -# https://dart.dev/guides/language/analysis-options 1 +include: package:lint/analysis_options.yaml
@@ -42,7 +42,7 @@ class _BarcodeScannerWithControllerState @@ -42,7 +42,7 @@ class _BarcodeScannerWithControllerState
42 setState(() { 42 setState(() {
43 this.barcode = barcode.rawValue; 43 this.barcode = barcode.rawValue;
44 }); 44 });
45 - }), 45 + },),
46 Align( 46 Align(
47 alignment: Alignment.bottomCenter, 47 alignment: Alignment.bottomCenter,
48 child: Container( 48 child: Container(
@@ -50,7 +50,6 @@ class _BarcodeScannerWithControllerState @@ -50,7 +50,6 @@ class _BarcodeScannerWithControllerState
50 height: 100, 50 height: 100,
51 color: Colors.black.withOpacity(0.4), 51 color: Colors.black.withOpacity(0.4),
52 child: Row( 52 child: Row(
53 - crossAxisAlignment: CrossAxisAlignment.center,  
54 mainAxisAlignment: MainAxisAlignment.spaceEvenly, 53 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
55 children: [ 54 children: [
56 IconButton( 55 IconButton(
@@ -58,13 +57,17 @@ class _BarcodeScannerWithControllerState @@ -58,13 +57,17 @@ class _BarcodeScannerWithControllerState
58 icon: ValueListenableBuilder( 57 icon: ValueListenableBuilder(
59 valueListenable: controller.torchState, 58 valueListenable: controller.torchState,
60 builder: (context, state, child) { 59 builder: (context, state, child) {
  60 + if (state == null) {
  61 + return const Icon(Icons.flash_off,
  62 + color: Colors.grey,);
  63 + }
61 switch (state as TorchState) { 64 switch (state as TorchState) {
62 case TorchState.off: 65 case TorchState.off:
63 return const Icon(Icons.flash_off, 66 return const Icon(Icons.flash_off,
64 - color: Colors.grey); 67 + color: Colors.grey,);
65 case TorchState.on: 68 case TorchState.on:
66 return const Icon(Icons.flash_on, 69 return const Icon(Icons.flash_on,
67 - color: Colors.yellow); 70 + color: Colors.yellow,);
68 } 71 }
69 }, 72 },
70 ), 73 ),
@@ -82,7 +85,7 @@ class _BarcodeScannerWithControllerState @@ -82,7 +85,7 @@ class _BarcodeScannerWithControllerState
82 ? controller.stop() 85 ? controller.stop()
83 : controller.start(); 86 : controller.start();
84 isStarted = !isStarted; 87 isStarted = !isStarted;
85 - })), 88 + }),),
86 Center( 89 Center(
87 child: SizedBox( 90 child: SizedBox(
88 width: MediaQuery.of(context).size.width - 200, 91 width: MediaQuery.of(context).size.width - 200,
@@ -104,6 +107,9 @@ class _BarcodeScannerWithControllerState @@ -104,6 +107,9 @@ class _BarcodeScannerWithControllerState
104 icon: ValueListenableBuilder( 107 icon: ValueListenableBuilder(
105 valueListenable: controller.cameraFacingState, 108 valueListenable: controller.cameraFacingState,
106 builder: (context, state, child) { 109 builder: (context, state, child) {
  110 + if (state == null) {
  111 + return const Icon(Icons.camera_front);
  112 + }
107 switch (state as CameraFacing) { 113 switch (state as CameraFacing) {
108 case CameraFacing.front: 114 case CameraFacing.front:
109 return const Icon(Icons.camera_front); 115 return const Icon(Icons.camera_front);
@@ -123,20 +129,22 @@ class _BarcodeScannerWithControllerState @@ -123,20 +129,22 @@ class _BarcodeScannerWithControllerState
123 final ImagePicker _picker = ImagePicker(); 129 final ImagePicker _picker = ImagePicker();
124 // Pick an image 130 // Pick an image
125 final XFile? image = await _picker.pickImage( 131 final XFile? image = await _picker.pickImage(
126 - source: ImageSource.gallery); 132 + source: ImageSource.gallery,);
127 if (image != null) { 133 if (image != null) {
128 if (await controller.analyzeImage(image.path)) { 134 if (await controller.analyzeImage(image.path)) {
  135 + if (!mounted) return;
129 ScaffoldMessenger.of(context) 136 ScaffoldMessenger.of(context)
130 .showSnackBar(const SnackBar( 137 .showSnackBar(const SnackBar(
131 content: Text('Barcode found!'), 138 content: Text('Barcode found!'),
132 backgroundColor: Colors.green, 139 backgroundColor: Colors.green,
133 - )); 140 + ),);
134 } else { 141 } else {
  142 + if (!mounted) return;
135 ScaffoldMessenger.of(context) 143 ScaffoldMessenger.of(context)
136 .showSnackBar(const SnackBar( 144 .showSnackBar(const SnackBar(
137 content: Text('No barcode found!'), 145 content: Text('No barcode found!'),
138 backgroundColor: Colors.red, 146 backgroundColor: Colors.red,
139 - )); 147 + ),);
140 } 148 }
141 } 149 }
142 }, 150 },
@@ -147,7 +155,7 @@ class _BarcodeScannerWithControllerState @@ -147,7 +155,7 @@ class _BarcodeScannerWithControllerState
147 ), 155 ),
148 ], 156 ],
149 ); 157 );
150 - }), 158 + },),
151 ); 159 );
152 } 160 }
153 } 161 }
@@ -28,7 +28,7 @@ class _BarcodeScannerWithoutControllerState @@ -28,7 +28,7 @@ class _BarcodeScannerWithoutControllerState
28 setState(() { 28 setState(() {
29 this.barcode = barcode.rawValue; 29 this.barcode = barcode.rawValue;
30 }); 30 });
31 - }), 31 + },),
32 Align( 32 Align(
33 alignment: Alignment.bottomCenter, 33 alignment: Alignment.bottomCenter,
34 child: Container( 34 child: Container(
@@ -36,7 +36,6 @@ class _BarcodeScannerWithoutControllerState @@ -36,7 +36,6 @@ class _BarcodeScannerWithoutControllerState
36 height: 100, 36 height: 100,
37 color: Colors.black.withOpacity(0.4), 37 color: Colors.black.withOpacity(0.4),
38 child: Row( 38 child: Row(
39 - crossAxisAlignment: CrossAxisAlignment.center,  
40 mainAxisAlignment: MainAxisAlignment.spaceEvenly, 39 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
41 children: [ 40 children: [
42 Center( 41 Center(
@@ -61,7 +60,7 @@ class _BarcodeScannerWithoutControllerState @@ -61,7 +60,7 @@ class _BarcodeScannerWithoutControllerState
61 ), 60 ),
62 ], 61 ],
63 ); 62 );
64 - }), 63 + },),
65 ); 64 );
66 } 65 }
67 } 66 }
@@ -16,13 +16,12 @@ class MyHome extends StatelessWidget { @@ -16,13 +16,12 @@ class MyHome extends StatelessWidget {
16 height: MediaQuery.of(context).size.height, 16 height: MediaQuery.of(context).size.height,
17 child: Column( 17 child: Column(
18 mainAxisAlignment: MainAxisAlignment.center, 18 mainAxisAlignment: MainAxisAlignment.center,
19 - crossAxisAlignment: CrossAxisAlignment.center,  
20 children: [ 19 children: [
21 ElevatedButton( 20 ElevatedButton(
22 onPressed: () { 21 onPressed: () {
23 Navigator.of(context).push(MaterialPageRoute( 22 Navigator.of(context).push(MaterialPageRoute(
24 builder: (context) => const BarcodeScannerWithController(), 23 builder: (context) => const BarcodeScannerWithController(),
25 - )); 24 + ),);
26 }, 25 },
27 child: const Text('MobileScanner with Controller'), 26 child: const Text('MobileScanner with Controller'),
28 ), 27 ),
@@ -30,7 +29,7 @@ class MyHome extends StatelessWidget { @@ -30,7 +29,7 @@ class MyHome extends StatelessWidget {
30 onPressed: () { 29 onPressed: () {
31 Navigator.of(context).push(MaterialPageRoute( 30 Navigator.of(context).push(MaterialPageRoute(
32 builder: (context) => const BarcodeScannerWithoutController(), 31 builder: (context) => const BarcodeScannerWithoutController(),
33 - )); 32 + ),);
34 }, 33 },
35 child: const Text('MobileScanner without Controller'), 34 child: const Text('MobileScanner without Controller'),
36 ), 35 ),
@@ -6,9 +6,9 @@ environment: @@ -6,9 +6,9 @@ environment:
6 sdk: ">=2.12.0 <3.0.0" 6 sdk: ">=2.12.0 <3.0.0"
7 7
8 dependencies: 8 dependencies:
9 - image_picker: ^0.8.4+9  
10 flutter: 9 flutter:
11 sdk: flutter 10 sdk: flutter
  11 + image_picker: ^0.8.4+9
12 12
13 mobile_scanner: 13 mobile_scanner:
14 path: ../ 14 path: ../
@@ -16,7 +16,7 @@ dependencies: @@ -16,7 +16,7 @@ dependencies:
16 dev_dependencies: 16 dev_dependencies:
17 flutter_test: 17 flutter_test:
18 sdk: flutter 18 sdk: flutter
19 - flutter_lints: ^1.0.4 19 + lint: ^1.8.2
20 20
21 flutter: 21 flutter:
22 uses-material-design: true 22 uses-material-design: true
1 library mobile_scanner; 1 library mobile_scanner;
2 2
3 export 'src/mobile_scanner.dart'; 3 export 'src/mobile_scanner.dart';
4 -export 'src/mobile_scanner_controller.dart';  
5 export 'src/mobile_scanner_arguments.dart'; 4 export 'src/mobile_scanner_arguments.dart';
  5 +export 'src/mobile_scanner_controller.dart';
6 export 'src/objects/barcode.dart'; 6 export 'src/objects/barcode.dart';
1 import 'dart:async'; 1 import 'dart:async';
  2 +import 'dart:html' as html;
  3 +import 'dart:ui' as ui;
2 4
3 import 'package:flutter/material.dart'; 5 import 'package:flutter/material.dart';
4 import 'package:flutter/services.dart'; 6 import 'package:flutter/services.dart';
5 import 'package:flutter_web_plugins/flutter_web_plugins.dart'; 7 import 'package:flutter_web_plugins/flutter_web_plugins.dart';
6 import 'package:mobile_scanner/mobile_scanner.dart'; 8 import 'package:mobile_scanner/mobile_scanner.dart';
7 import 'package:mobile_scanner/src/web/jsqr.dart'; 9 import 'package:mobile_scanner/src/web/jsqr.dart';
8 -import 'dart:html' as html;  
9 -import 'dart:ui' as ui;  
10 -  
11 import 'package:mobile_scanner/src/web/media.dart'; 10 import 'package:mobile_scanner/src/web/media.dart';
12 11
13 /// This plugin is the web implementation of mobile_scanner. 12 /// This plugin is the web implementation of mobile_scanner.
14 /// It only supports QR codes. 13 /// It only supports QR codes.
15 class MobileScannerWebPlugin { 14 class MobileScannerWebPlugin {
16 static void registerWith(Registrar registrar) { 15 static void registerWith(Registrar registrar) {
17 - PluginEventChannel event = PluginEventChannel( 16 + final PluginEventChannel event = PluginEventChannel(
18 'dev.steenbakker.mobile_scanner/scanner/event', 17 'dev.steenbakker.mobile_scanner/scanner/event',
19 const StandardMethodCodec(), 18 const StandardMethodCodec(),
20 - registrar);  
21 - MethodChannel channel = MethodChannel( 19 + registrar,);
  20 + final MethodChannel channel = MethodChannel(
22 'dev.steenbakker.mobile_scanner/scanner/method', 21 'dev.steenbakker.mobile_scanner/scanner/method',
23 const StandardMethodCodec(), 22 const StandardMethodCodec(),
24 - registrar); 23 + registrar,);
25 final MobileScannerWebPlugin instance = MobileScannerWebPlugin(); 24 final MobileScannerWebPlugin instance = MobileScannerWebPlugin();
26 WidgetsFlutterBinding.ensureInitialized(); 25 WidgetsFlutterBinding.ensureInitialized();
27 26
@@ -51,16 +50,16 @@ class MobileScannerWebPlugin { @@ -51,16 +50,16 @@ class MobileScannerWebPlugin {
51 Future<dynamic> handleMethodCall(MethodCall call) async { 50 Future<dynamic> handleMethodCall(MethodCall call) async {
52 switch (call.method) { 51 switch (call.method) {
53 case 'start': 52 case 'start':
54 - return await _start(call.arguments); 53 + return _start(call.arguments as Map<String, dynamic>);
55 case 'torch': 54 case 'torch':
56 - return await _torch(call.arguments); 55 + return _torch(call.arguments);
57 case 'stop': 56 case 'stop':
58 - return await cancel(); 57 + return cancel();
59 default: 58 default:
60 throw PlatformException( 59 throw PlatformException(
61 code: 'Unimplemented', 60 code: 'Unimplemented',
62 details: "The mobile_scanner plugin for web doesn't implement " 61 details: "The mobile_scanner plugin for web doesn't implement "
63 - "the method '${call.method}'"); 62 + "the method '${call.method}'",);
64 } 63 }
65 } 64 }
66 65
@@ -77,21 +76,21 @@ class MobileScannerWebPlugin { @@ -77,21 +76,21 @@ class MobileScannerWebPlugin {
77 } 76 }
78 77
79 /// Starts the video stream and the scanner 78 /// Starts the video stream and the scanner
80 - Future<Map> _start(arguments) async { 79 + Future<Map> _start(Map<String, dynamic> arguments) async {
81 vidDiv.children = [video]; 80 vidDiv.children = [video];
82 81
83 var cameraFacing = CameraFacing.front; 82 var cameraFacing = CameraFacing.front;
84 if (arguments.containsKey('facing')) { 83 if (arguments.containsKey('facing')) {
85 - cameraFacing = CameraFacing.values[arguments['facing']]; 84 + cameraFacing = CameraFacing.values[arguments['facing'] as int];
86 } 85 }
87 86
88 // See https://github.com/flutter/flutter/issues/41563 87 // See https://github.com/flutter/flutter/issues/41563
89 - // ignore: UNDEFINED_PREFIXED_NAME 88 + // ignore: UNDEFINED_PREFIXED_NAME, avoid_dynamic_calls
90 ui.platformViewRegistry.registerViewFactory( 89 ui.platformViewRegistry.registerViewFactory(
91 viewID, 90 viewID,
92 (int id) => vidDiv 91 (int id) => vidDiv
93 ..style.width = '100%' 92 ..style.width = '100%'
94 - ..style.height = '100%'); 93 + ..style.height = '100%',);
95 94
96 // Check if stream is running 95 // Check if stream is running
97 if (_localStream != null) { 96 if (_localStream != null) {
@@ -104,13 +103,13 @@ class MobileScannerWebPlugin { @@ -104,13 +103,13 @@ class MobileScannerWebPlugin {
104 103
105 try { 104 try {
106 // Check if browser supports multiple camera's and set if supported 105 // Check if browser supports multiple camera's and set if supported
107 - Map? capabilities = 106 + final Map? capabilities =
108 html.window.navigator.mediaDevices?.getSupportedConstraints(); 107 html.window.navigator.mediaDevices?.getSupportedConstraints();
109 - if (capabilities != null && capabilities['facingMode']) {  
110 - var constraints = { 108 + if (capabilities != null && capabilities['facingMode'] as bool) {
  109 + final constraints = {
111 'video': VideoOptions( 110 'video': VideoOptions(
112 facingMode: 111 facingMode:
113 - (cameraFacing == CameraFacing.front ? 'user' : 'environment')) 112 + cameraFacing == CameraFacing.front ? 'user' : 'environment',)
114 }; 113 };
115 114
116 _localStream = 115 _localStream =
@@ -156,6 +155,8 @@ class MobileScannerWebPlugin { @@ -156,6 +155,8 @@ class MobileScannerWebPlugin {
156 final sources = 155 final sources =
157 await html.window.navigator.mediaDevices!.enumerateDevices(); 156 await html.window.navigator.mediaDevices!.enumerateDevices();
158 for (final e in sources) { 157 for (final e in sources) {
  158 + // TODO:
  159 + // ignore: avoid_dynamic_calls
159 if (e.kind == 'videoinput') { 160 if (e.kind == 'videoinput') {
160 return true; 161 return true;
161 } 162 }
@@ -33,7 +33,7 @@ class MobileScanner extends StatefulWidget { @@ -33,7 +33,7 @@ class MobileScanner extends StatefulWidget {
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}) 36 + this.allowDuplicates = false, })
37 : super(key: key); 37 : super(key: key);
38 38
39 @override 39 @override
@@ -81,10 +81,10 @@ class _MobileScannerState extends State<MobileScanner> @@ -81,10 +81,10 @@ class _MobileScannerState extends State<MobileScanner>
81 if (!widget.allowDuplicates) { 81 if (!widget.allowDuplicates) {
82 if (lastScanned != barcode.rawValue) { 82 if (lastScanned != barcode.rawValue) {
83 lastScanned = barcode.rawValue; 83 lastScanned = barcode.rawValue;
84 - widget.onDetect!(barcode, value as MobileScannerArguments); 84 + widget.onDetect!(barcode, value! as MobileScannerArguments);
85 } 85 }
86 } else { 86 } else {
87 - widget.onDetect!(barcode, value as MobileScannerArguments); 87 + widget.onDetect!(barcode, value! as MobileScannerArguments);
88 } 88 }
89 }); 89 });
90 return ClipRect( 90 return ClipRect(
@@ -104,8 +104,8 @@ class _MobileScannerState extends State<MobileScanner> @@ -104,8 +104,8 @@ class _MobileScannerState extends State<MobileScanner>
104 ), 104 ),
105 ); 105 );
106 } 106 }
107 - });  
108 - }); 107 + },);
  108 + },);
109 } 109 }
110 110
111 @override 111 @override
@@ -14,5 +14,5 @@ class MobileScannerArguments { @@ -14,5 +14,5 @@ class MobileScannerArguments {
14 14
15 /// Create a [MobileScannerArguments]. 15 /// Create a [MobileScannerArguments].
16 MobileScannerArguments( 16 MobileScannerArguments(
17 - {this.textureId, required this.size, required this.hasTorch, this.webId}); 17 + {this.textureId, required this.size, required this.hasTorch, this.webId, });
18 } 18 }
@@ -5,8 +5,7 @@ import 'package:flutter/cupertino.dart'; @@ -5,8 +5,7 @@ import 'package:flutter/cupertino.dart';
5 import 'package:flutter/foundation.dart'; 5 import 'package:flutter/foundation.dart';
6 import 'package:flutter/services.dart'; 6 import 'package:flutter/services.dart';
7 import 'package:mobile_scanner/mobile_scanner.dart'; 7 import 'package:mobile_scanner/mobile_scanner.dart';
8 -  
9 -import 'objects/barcode_utility.dart'; 8 +import 'package:mobile_scanner/src/objects/barcode_utility.dart';
10 9
11 /// The facing of a camera. 10 /// The facing of a camera.
12 enum CameraFacing { 11 enum CameraFacing {
@@ -60,7 +59,7 @@ class MobileScannerController { @@ -60,7 +59,7 @@ class MobileScannerController {
60 {this.facing = CameraFacing.back, 59 {this.facing = CameraFacing.back,
61 this.ratio, 60 this.ratio,
62 this.torchEnabled, 61 this.torchEnabled,
63 - this.formats}) { 62 + this.formats, }) {
64 // In case a new instance is created before calling dispose() 63 // In case a new instance is created before calling dispose()
65 if (_controllerHashcode != null) { 64 if (_controllerHashcode != null) {
66 stop(); 65 stop();
@@ -80,26 +79,26 @@ class MobileScannerController { @@ -80,26 +79,26 @@ class MobileScannerController {
80 // Listen to events from the platform specific code 79 // Listen to events from the platform specific code
81 events = eventChannel 80 events = eventChannel
82 .receiveBroadcastStream() 81 .receiveBroadcastStream()
83 - .listen((data) => handleEvent(data)); 82 + .listen((data) => handleEvent(data as Map));
84 } 83 }
85 84
86 - void handleEvent(Map<dynamic, dynamic> event) { 85 + void handleEvent(Map event) {
87 final name = event['name']; 86 final name = event['name'];
88 final data = event['data']; 87 final data = event['data'];
89 switch (name) { 88 switch (name) {
90 case 'torchState': 89 case 'torchState':
91 - final state = TorchState.values[data]; 90 + final state = TorchState.values[data as int];
92 torchState.value = state; 91 torchState.value = state;
93 break; 92 break;
94 case 'barcode': 93 case 'barcode':
95 - final barcode = Barcode.fromNative(data); 94 + final barcode = Barcode.fromNative(data as Map<String, dynamic>);
96 barcodesController.add(barcode); 95 barcodesController.add(barcode);
97 break; 96 break;
98 case 'barcodeMac': 97 case 'barcodeMac':
99 - barcodesController.add(Barcode(rawValue: data['payload'])); 98 + barcodesController.add(Barcode(rawValue: (data as Map<String, dynamic>)['payload'] as String));
100 break; 99 break;
101 case 'barcodeWeb': 100 case 'barcodeWeb':
102 - barcodesController.add(Barcode(rawValue: data)); 101 + barcodesController.add(Barcode(rawValue: data as String));
103 break; 102 break;
104 default: 103 default:
105 throw UnimplementedError(); 104 throw UnimplementedError();
@@ -130,10 +129,10 @@ class MobileScannerController { @@ -130,10 +129,10 @@ class MobileScannerController {
130 // Check authorization status 129 // Check authorization status
131 if (!kIsWeb) { 130 if (!kIsWeb) {
132 MobileScannerState state = 131 MobileScannerState state =
133 - MobileScannerState.values[await methodChannel.invokeMethod('state')]; 132 + MobileScannerState.values[await methodChannel.invokeMethod('state') as int];
134 switch (state) { 133 switch (state) {
135 case MobileScannerState.undetermined: 134 case MobileScannerState.undetermined:
136 - final bool result = await methodChannel.invokeMethod('request'); 135 + final bool result = await methodChannel.invokeMethod('request') as bool;
137 state = result 136 state = result
138 ? MobileScannerState.authorized 137 ? MobileScannerState.authorized
139 : MobileScannerState.denied; 138 : MobileScannerState.denied;
@@ -149,7 +148,7 @@ class MobileScannerController { @@ -149,7 +148,7 @@ class MobileScannerController {
149 cameraFacingState.value = facing; 148 cameraFacingState.value = facing;
150 149
151 // Set the starting arguments for the camera 150 // Set the starting arguments for the camera
152 - Map arguments = {}; 151 + final Map arguments = {};
153 arguments['facing'] = facing.index; 152 arguments['facing'] = facing.index;
154 if (ratio != null) arguments['ratio'] = ratio; 153 if (ratio != null) arguments['ratio'] = ratio;
155 if (torchEnabled != null) arguments['torch'] = torchEnabled; 154 if (torchEnabled != null) arguments['torch'] = torchEnabled;
@@ -166,7 +165,7 @@ class MobileScannerController { @@ -166,7 +165,7 @@ class MobileScannerController {
166 Map<String, dynamic>? startResult = {}; 165 Map<String, dynamic>? startResult = {};
167 try { 166 try {
168 startResult = await methodChannel.invokeMapMethod<String, dynamic>( 167 startResult = await methodChannel.invokeMapMethod<String, dynamic>(
169 - 'start', arguments); 168 + 'start', arguments,);
170 } on PlatformException catch (error) { 169 } on PlatformException catch (error) {
171 debugPrint('${error.code}: ${error.message}'); 170 debugPrint('${error.code}: ${error.message}');
172 isStarting = false; 171 isStarting = false;
@@ -179,18 +178,18 @@ class MobileScannerController { @@ -179,18 +178,18 @@ class MobileScannerController {
179 throw PlatformException(code: 'INITIALIZATION ERROR'); 178 throw PlatformException(code: 'INITIALIZATION ERROR');
180 } 179 }
181 180
182 - hasTorch = startResult['torchable']; 181 + hasTorch = startResult['torchable'] as bool;
183 182
184 if (kIsWeb) { 183 if (kIsWeb) {
185 args.value = MobileScannerArguments( 184 args.value = MobileScannerArguments(
186 - webId: startResult['ViewID'],  
187 - size: Size(startResult['videoWidth'], startResult['videoHeight']),  
188 - hasTorch: hasTorch); 185 + webId: startResult['ViewID'] as String?,
  186 + size: Size(startResult['videoWidth'] as double, startResult['videoHeight'] as double),
  187 + hasTorch: hasTorch,);
189 } else { 188 } else {
190 args.value = MobileScannerArguments( 189 args.value = MobileScannerArguments(
191 - textureId: startResult['textureId'],  
192 - size: toSize(startResult['size']),  
193 - hasTorch: hasTorch); 190 + textureId: startResult['textureId'] as int,
  191 + size: toSize(startResult['size'] as Map<String, double>),
  192 + hasTorch: hasTorch,);
194 } 193 }
195 194
196 isStarting = false; 195 isStarting = false;
@@ -214,7 +213,7 @@ class MobileScannerController { @@ -214,7 +213,7 @@ class MobileScannerController {
214 return; 213 return;
215 } 214 }
216 215
217 - TorchState state = 216 + final TorchState state =
218 torchState.value == TorchState.off ? TorchState.on : TorchState.off; 217 torchState.value == TorchState.off ? TorchState.on : TorchState.off;
219 218
220 try { 219 try {
@@ -233,7 +232,7 @@ class MobileScannerController { @@ -233,7 +232,7 @@ class MobileScannerController {
233 await methodChannel.invokeMethod('stop'); 232 await methodChannel.invokeMethod('stop');
234 } on PlatformException catch (error) { 233 } on PlatformException catch (error) {
235 debugPrint( 234 debugPrint(
236 - '${error.code}: camera is stopped! Please start before switching camera.'); 235 + '${error.code}: camera is stopped! Please start before switching camera.',);
237 return; 236 return;
238 } 237 }
239 facing = 238 facing =
@@ -247,7 +246,7 @@ class MobileScannerController { @@ -247,7 +246,7 @@ class MobileScannerController {
247 /// 246 ///
248 /// [path] The path of the image on the devices 247 /// [path] The path of the image on the devices
249 Future<bool> analyzeImage(String path) async { 248 Future<bool> analyzeImage(String path) async {
250 - return await methodChannel.invokeMethod('analyzeImage', path); 249 + return methodChannel.invokeMethod('analyzeImage', path) as bool;
251 } 250 }
252 251
253 /// Disposes the MobileScannerController and closes all listeners. 252 /// Disposes the MobileScannerController and closes all listeners.
1 import 'dart:typed_data'; 1 import 'dart:typed_data';
2 import 'dart:ui'; 2 import 'dart:ui';
3 3
4 -import 'barcode_utility.dart'; 4 +import 'package:mobile_scanner/src/objects/barcode_utility.dart';
5 5
6 /// Represents a single recognized barcode and its value. 6 /// Represents a single recognized barcode and its value.
7 class Barcode { 7 class Barcode {
@@ -77,24 +77,24 @@ class Barcode { @@ -77,24 +77,24 @@ 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 /// Create a [Barcode] from native data. 82 /// Create a [Barcode] from native data.
83 - Barcode.fromNative(Map<dynamic, dynamic> data)  
84 - : corners = toCorners(data['corners']),  
85 - format = toFormat(data['format']),  
86 - rawBytes = data['rawBytes'],  
87 - rawValue = data['rawValue'],  
88 - type = BarcodeType.values[data['type']],  
89 - calendarEvent = toCalendarEvent(data['calendarEvent']),  
90 - contactInfo = toContactInfo(data['contactInfo']),  
91 - driverLicense = toDriverLicense(data['driverLicense']),  
92 - email = toEmail(data['email']),  
93 - geoPoint = toGeoPoint(data['geoPoint']),  
94 - phone = toPhone(data['phone']),  
95 - sms = toSMS(data['sms']),  
96 - url = toUrl(data['url']),  
97 - wifi = toWiFi(data['wifi']); 83 + Barcode.fromNative(Map<String, dynamic> data)
  84 + : corners = toCorners(data['corners'] as List<Map>?),
  85 + format = toFormat(data['format'] as int),
  86 + rawBytes = data['rawBytes'] as Uint8List?,
  87 + rawValue = data['rawValue'] as String?,
  88 + type = BarcodeType.values[data['type'] as int],
  89 + calendarEvent = toCalendarEvent(data['calendarEvent'] as Map<String, String?>?),
  90 + contactInfo = toContactInfo(data['contactInfo'] as Map?),
  91 + driverLicense = toDriverLicense(data['driverLicense'] as Map?),
  92 + email = toEmail(data['email'] as Map?),
  93 + geoPoint = toGeoPoint(data['geoPoint'] as Map?),
  94 + phone = toPhone(data['phone'] as Map?),
  95 + sms = toSMS(data['sms'] as Map?),
  96 + url = toUrl(data['url'] as Map?),
  97 + wifi = toWiFi(data['wifi'] as Map?);
98 } 98 }
99 99
100 /// A calendar event extracted from QRCode. 100 /// A calendar event extracted from QRCode.
@@ -135,10 +135,10 @@ class CalendarEvent { @@ -135,10 +135,10 @@ class CalendarEvent {
135 final String? summary; 135 final String? summary;
136 136
137 /// Create a [CalendarEvent] from native data. 137 /// Create a [CalendarEvent] from native data.
138 - CalendarEvent.fromNative(Map<dynamic, dynamic> data) 138 + CalendarEvent.fromNative(Map<dynamic, String?> data)
139 : description = data['description'], 139 : description = data['description'],
140 - start = DateTime.tryParse(data['start']),  
141 - end = DateTime.tryParse(data['end']), 140 + start = DateTime.tryParse(data['start']!),
  141 + end = DateTime.tryParse(data['end']!),
142 location = data['location'], 142 location = data['location'],
143 organizer = data['organizer'], 143 organizer = data['organizer'],
144 status = data['status'], 144 status = data['status'],
@@ -185,15 +185,15 @@ class ContactInfo { @@ -185,15 +185,15 @@ class ContactInfo {
185 /// Create a [ContactInfo] from native data. 185 /// Create a [ContactInfo] from native data.
186 ContactInfo.fromNative(Map<dynamic, dynamic> data) 186 ContactInfo.fromNative(Map<dynamic, dynamic> data)
187 : addresses = List.unmodifiable( 187 : addresses = List.unmodifiable(
188 - data['addresses'].map((e) => Address.fromNative(e))), 188 + (data['addresses'] as List<Map>).map((e) => Address.fromNative(e)),),
189 emails = 189 emails =
190 - List.unmodifiable(data['emails'].map((e) => Email.fromNative(e))),  
191 - name = toName(data['name']),  
192 - organization = data['organization'], 190 + List.unmodifiable((data['emails'] as List<Map>).map((e) => Email.fromNative(e))),
  191 + name = toName(data['name'] as Map?),
  192 + organization = data['organization'] as String?,
193 phones = 193 phones =
194 - List.unmodifiable(data['phones'].map((e) => Phone.fromNative(e))),  
195 - title = data['title'],  
196 - urls = List.unmodifiable(data['urls']); 194 + List.unmodifiable((data['phones'] as List<Map>).map((e) => Phone.fromNative(e))),
  195 + title = data['title'] as String?,
  196 + urls = List.unmodifiable(data['urls'] as List);
197 } 197 }
198 198
199 /// An address. 199 /// An address.
@@ -208,8 +208,8 @@ class Address { @@ -208,8 +208,8 @@ class Address {
208 208
209 /// Create a [Address] from native data. 209 /// Create a [Address] from native data.
210 Address.fromNative(Map<dynamic, dynamic> data) 210 Address.fromNative(Map<dynamic, dynamic> data)
211 - : addressLines = List.unmodifiable(data['addressLines']),  
212 - type = AddressType.values[data['type']]; 211 + : addressLines = List.unmodifiable(data['addressLines'] as List),
  212 + type = AddressType.values[data['type'] as int];
213 } 213 }
214 214
215 /// A person's name, both formatted version and individual name components. 215 /// A person's name, both formatted version and individual name components.
@@ -251,13 +251,13 @@ class PersonName { @@ -251,13 +251,13 @@ class PersonName {
251 251
252 /// Create a [PersonName] from native data. 252 /// Create a [PersonName] from native data.
253 PersonName.fromNative(Map<dynamic, dynamic> data) 253 PersonName.fromNative(Map<dynamic, dynamic> data)
254 - : first = data['first'],  
255 - middle = data['middle'],  
256 - last = data['last'],  
257 - prefix = data['prefix'],  
258 - suffix = data['suffix'],  
259 - formattedName = data['formattedName'],  
260 - pronunciation = data['pronunciation']; 254 + : first = data['first'] as String?,
  255 + middle = data['middle'] as String?,
  256 + last = data['last'] as String?,
  257 + prefix = data['prefix'] as String?,
  258 + suffix = data['suffix'] as String?,
  259 + formattedName = data['formattedName'] as String?,
  260 + pronunciation = data['pronunciation'] as String?;
261 } 261 }
262 262
263 /// A driver license or ID card. 263 /// A driver license or ID card.
@@ -336,20 +336,20 @@ class DriverLicense { @@ -336,20 +336,20 @@ class DriverLicense {
336 336
337 /// Create a [DriverLicense] from native data. 337 /// Create a [DriverLicense] from native data.
338 DriverLicense.fromNative(Map<dynamic, dynamic> data) 338 DriverLicense.fromNative(Map<dynamic, dynamic> data)
339 - : addressCity = data['addressCity'],  
340 - addressState = data['addressState'],  
341 - addressStreet = data['addressStreet'],  
342 - addressZip = data['addressZip'],  
343 - birthDate = data['birthDate'],  
344 - documentType = data['documentType'],  
345 - expiryDate = data['expiryDate'],  
346 - firstName = data['firstName'],  
347 - gender = data['gender'],  
348 - issueDate = data['issueDate'],  
349 - issuingCountry = data['issuingCountry'],  
350 - lastName = data['lastName'],  
351 - licenseNumber = data['licenseNumber'],  
352 - middleName = data['middleName']; 339 + : addressCity = data['addressCity'] as String?,
  340 + addressState = data['addressState'] as String?,
  341 + addressStreet = data['addressStreet'] as String?,
  342 + addressZip = data['addressZip'] as String?,
  343 + birthDate = data['birthDate'] as String?,
  344 + documentType = data['documentType'] as String?,
  345 + expiryDate = data['expiryDate'] as String?,
  346 + firstName = data['firstName'] as String?,
  347 + gender = data['gender'] as String?,
  348 + issueDate = data['issueDate'] as String?,
  349 + issuingCountry = data['issuingCountry'] as String?,
  350 + lastName = data['lastName'] as String?,
  351 + licenseNumber = data['licenseNumber'] as String?,
  352 + middleName = data['middleName'] as String?;
353 } 353 }
354 354
355 /// An email message from a 'MAILTO:' or similar QRCode type. 355 /// An email message from a 'MAILTO:' or similar QRCode type.
@@ -377,10 +377,10 @@ class Email { @@ -377,10 +377,10 @@ class Email {
377 377
378 /// Create a [Email] from native data. 378 /// Create a [Email] from native data.
379 Email.fromNative(Map<dynamic, dynamic> data) 379 Email.fromNative(Map<dynamic, dynamic> data)
380 - : address = data['address'],  
381 - body = data['body'],  
382 - subject = data['subject'],  
383 - type = EmailType.values[data['type']]; 380 + : address = data['address'] as String?,
  381 + body = data['body'] as String?,
  382 + subject = data['subject'] as String?,
  383 + type = EmailType.values[data['type'] as int];
384 } 384 }
385 385
386 /// GPS coordinates from a 'GEO:' or similar QRCode type. 386 /// GPS coordinates from a 'GEO:' or similar QRCode type.
@@ -393,8 +393,8 @@ class GeoPoint { @@ -393,8 +393,8 @@ class GeoPoint {
393 393
394 /// Create a [GeoPoint] from native data. 394 /// Create a [GeoPoint] from native data.
395 GeoPoint.fromNative(Map<dynamic, dynamic> data) 395 GeoPoint.fromNative(Map<dynamic, dynamic> data)
396 - : latitude = data['latitude'],  
397 - longitude = data['longitude']; 396 + : latitude = data['latitude'] as double?,
  397 + longitude = data['longitude'] as double?;
398 } 398 }
399 399
400 /// Phone number info. 400 /// Phone number info.
@@ -412,8 +412,8 @@ class Phone { @@ -412,8 +412,8 @@ class Phone {
412 412
413 /// Create a [Phone] from native data. 413 /// Create a [Phone] from native data.
414 Phone.fromNative(Map<dynamic, dynamic> data) 414 Phone.fromNative(Map<dynamic, dynamic> data)
415 - : number = data['number'],  
416 - type = PhoneType.values[data['type']]; 415 + : number = data['number'] as String?,
  416 + type = PhoneType.values[data['type'] as int];
417 } 417 }
418 418
419 /// A sms message from a 'SMS:' or similar QRCode type. 419 /// A sms message from a 'SMS:' or similar QRCode type.
@@ -430,8 +430,8 @@ class SMS { @@ -430,8 +430,8 @@ class SMS {
430 430
431 /// Create a [SMS] from native data. 431 /// Create a [SMS] from native data.
432 SMS.fromNative(Map<dynamic, dynamic> data) 432 SMS.fromNative(Map<dynamic, dynamic> data)
433 - : message = data['message'],  
434 - phoneNumber = data['phoneNumber']; 433 + : message = data['message'] as String?,
  434 + phoneNumber = data['phoneNumber'] as String?;
435 } 435 }
436 436
437 /// A URL and title from a 'MEBKM:' or similar QRCode type. 437 /// A URL and title from a 'MEBKM:' or similar QRCode type.
@@ -448,8 +448,8 @@ class UrlBookmark { @@ -448,8 +448,8 @@ class UrlBookmark {
448 448
449 /// Create a [UrlBookmark] from native data. 449 /// Create a [UrlBookmark] from native data.
450 UrlBookmark.fromNative(Map<dynamic, dynamic> data) 450 UrlBookmark.fromNative(Map<dynamic, dynamic> data)
451 - : title = data['title'],  
452 - url = data['url']; 451 + : title = data['title'] as String?,
  452 + url = data['url'] as String?;
453 } 453 }
454 454
455 /// A wifi network parameters from a 'WIFI:' or similar QRCode type. 455 /// A wifi network parameters from a 'WIFI:' or similar QRCode type.
@@ -471,9 +471,9 @@ class WiFi { @@ -471,9 +471,9 @@ class WiFi {
471 471
472 /// Create a [WiFi] from native data. 472 /// Create a [WiFi] from native data.
473 WiFi.fromNative(Map<dynamic, dynamic> data) 473 WiFi.fromNative(Map<dynamic, dynamic> data)
474 - : encryptionType = EncryptionType.values[data['encryptionType']],  
475 - ssid = data['ssid'],  
476 - password = data['password']; 474 + : encryptionType = EncryptionType.values[data['encryptionType'] as int],
  475 + ssid = data['ssid'] as String?,
  476 + password = data['password'] as String?;
477 } 477 }
478 478
479 enum BarcodeFormat { 479 enum BarcodeFormat {
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
  2 +import 'package:mobile_scanner/mobile_scanner.dart';
2 3
3 -import 'barcode.dart';  
4 4
5 -Size toSize(Map<dynamic, dynamic> data) {  
6 - final width = data['width'];  
7 - final height = data['height']; 5 +Size toSize(Map<dynamic, double> data) {
  6 + final width = data['width']!;
  7 + final height = data['height']!;
8 return Size(width, height); 8 return Size(width, height);
9 } 9 }
10 10
11 -List<Offset>? toCorners(List<dynamic>? data) { 11 +List<Offset>? toCorners(List<Map>? data) {
12 if (data != null) { 12 if (data != null) {
13 - return List.unmodifiable(data.map((e) => Offset(e['x'], e['y']))); 13 + return List.unmodifiable(data.map((e) => Offset(e['x'] as double, e['y'] as double)));
14 } else { 14 } else {
15 return null; 15 return null;
16 } 16 }
@@ -51,7 +51,7 @@ BarcodeFormat toFormat(int value) { @@ -51,7 +51,7 @@ BarcodeFormat toFormat(int value) {
51 } 51 }
52 } 52 }
53 53
54 -CalendarEvent? toCalendarEvent(Map<dynamic, dynamic>? data) { 54 +CalendarEvent? toCalendarEvent(Map<dynamic, String?>? data) {
55 if (data != null) { 55 if (data != null) {
56 return CalendarEvent.fromNative(data); 56 return CalendarEvent.fromNative(data);
57 } else { 57 } else {
@@ -59,15 +59,15 @@ CalendarEvent? toCalendarEvent(Map<dynamic, dynamic>? data) { @@ -59,15 +59,15 @@ CalendarEvent? toCalendarEvent(Map<dynamic, dynamic>? data) {
59 } 59 }
60 } 60 }
61 61
62 -DateTime? toDateTime(Map<dynamic, dynamic>? data) { 62 +DateTime? toDateTime(Map<String, dynamic>? data) {
63 if (data != null) { 63 if (data != null) {
64 - final year = data['year'];  
65 - final month = data['month'];  
66 - final day = data['day'];  
67 - final hour = data['hours'];  
68 - final minute = data['minutes'];  
69 - final second = data['seconds'];  
70 - return data['isUtc'] 64 + final year = data['year'] as int;
  65 + final month = data['month'] as int;
  66 + final day = data['day'] as int;
  67 + final hour = data['hours'] as int;
  68 + final minute = data['minutes'] as int;
  69 + final second = data['seconds'] as int;
  70 + return data['isUtc'] as bool
71 ? DateTime.utc(year, month, day, hour, minute, second) 71 ? DateTime.utc(year, month, day, hour, minute, second)
72 : DateTime(year, month, day, hour, minute, second); 72 : DateTime(year, month, day, hour, minute, second);
73 } else { 73 } else {
@@ -4,7 +4,7 @@ library jsqr; @@ -4,7 +4,7 @@ library jsqr;
4 import 'package:js/js.dart'; 4 import 'package:js/js.dart';
5 5
6 @JS('jsQR') 6 @JS('jsQR')
7 -external Code? jsQR(var data, int? width, int? height); 7 +external Code? jsQR(dynamic data, int? width, int? height);
8 8
9 @JS() 9 @JS()
10 class Code { 10 class Code {
@@ -26,7 +26,7 @@ class VideoOptions { @@ -26,7 +26,7 @@ class VideoOptions {
26 external Map get height; 26 external Map get height;
27 27
28 external factory VideoOptions( 28 external factory VideoOptions(
29 - {String? facingMode, DeviceIdOptions? deviceId, Map? width, Map? height}); 29 + {String? facingMode, DeviceIdOptions? deviceId, Map? width, Map? height, });
30 } 30 }
31 31
32 @JS() 32 @JS()
@@ -4,7 +4,7 @@ library qrscanner; @@ -4,7 +4,7 @@ library qrscanner;
4 import 'package:js/js.dart'; 4 import 'package:js/js.dart';
5 5
6 @JS('QrScanner') 6 @JS('QrScanner')
7 -external String scanImage(var data); 7 +external String scanImage(dynamic data);
8 8
9 @JS() 9 @JS()
10 class QrScanner { 10 class QrScanner {
@@ -8,16 +8,16 @@ environment: @@ -8,16 +8,16 @@ environment:
8 flutter: ">=1.10.0" 8 flutter: ">=1.10.0"
9 9
10 dependencies: 10 dependencies:
11 - js: ^0.6.3  
12 flutter: 11 flutter:
13 sdk: flutter 12 sdk: flutter
14 flutter_web_plugins: 13 flutter_web_plugins:
15 sdk: flutter 14 sdk: flutter
  15 + js: ^0.6.3
16 16
17 dev_dependencies: 17 dev_dependencies:
18 flutter_test: 18 flutter_test:
19 sdk: flutter 19 sdk: flutter
20 - flutter_lints: ^1.0.4 20 + lint: ^1.8.2
21 21
22 flutter: 22 flutter:
23 plugin: 23 plugin: