Julian Steenbakker

Merge branch 'feature/return-image-dart' into imp/return-image-ios

# Conflicts:
#	example/lib/barcode_scanner_controller.dart
@@ -13,7 +13,6 @@ class BarcodeListScannerWithController extends StatefulWidget { @@ -13,7 +13,6 @@ class BarcodeListScannerWithController extends StatefulWidget {
13 class _BarcodeListScannerWithControllerState 13 class _BarcodeListScannerWithControllerState
14 extends State<BarcodeListScannerWithController> 14 extends State<BarcodeListScannerWithController>
15 with SingleTickerProviderStateMixin { 15 with SingleTickerProviderStateMixin {
16 -  
17 BarcodeCapture? barcodeCapture; 16 BarcodeCapture? barcodeCapture;
18 17
19 MobileScannerController controller = MobileScannerController( 18 MobileScannerController controller = MobileScannerController(
@@ -13,12 +13,10 @@ class BarcodeScannerWithController extends StatefulWidget { @@ -13,12 +13,10 @@ class BarcodeScannerWithController extends StatefulWidget {
13 class _BarcodeScannerWithControllerState 13 class _BarcodeScannerWithControllerState
14 extends State<BarcodeScannerWithController> 14 extends State<BarcodeScannerWithController>
15 with SingleTickerProviderStateMixin { 15 with SingleTickerProviderStateMixin {
16 -  
17 BarcodeCapture? barcode; 16 BarcodeCapture? barcode;
18 17
19 MobileScannerController controller = MobileScannerController( 18 MobileScannerController controller = MobileScannerController(
20 - torchEnabled: true,  
21 - detectionSpeed: DetectionSpeed.normal 19 + torchEnabled: true, detectionSpeed: DetectionSpeed.unrestricted,
22 // formats: [BarcodeFormat.qrCode] 20 // formats: [BarcodeFormat.qrCode]
23 // facing: CameraFacing.front, 21 // facing: CameraFacing.front,
24 ); 22 );
@@ -101,7 +99,8 @@ class _BarcodeScannerWithControllerState @@ -101,7 +99,8 @@ class _BarcodeScannerWithControllerState
101 height: 50, 99 height: 50,
102 child: FittedBox( 100 child: FittedBox(
103 child: Text( 101 child: Text(
104 - barcode?.barcodes.first.rawValue ?? 'Scan something!', 102 + barcode?.barcodes.first.rawValue ??
  103 + 'Scan something!',
105 overflow: TextOverflow.fade, 104 overflow: TextOverflow.fade,
106 style: Theme.of(context) 105 style: Theme.of(context)
107 .textTheme 106 .textTheme
1 import 'dart:math'; 1 import 'dart:math';
2 -import 'dart:typed_data';  
3 2
4 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
5 import 'package:mobile_scanner/mobile_scanner.dart'; 4 import 'package:mobile_scanner/mobile_scanner.dart';
@@ -27,7 +26,6 @@ class _BarcodeScannerReturningImageState @@ -27,7 +26,6 @@ class _BarcodeScannerReturningImageState
27 26
28 bool isStarted = true; 27 bool isStarted = true;
29 28
30 -  
31 @override 29 @override
32 Widget build(BuildContext context) { 30 Widget build(BuildContext context) {
33 return Scaffold( 31 return Scaffold(
@@ -42,14 +40,21 @@ class _BarcodeScannerReturningImageState @@ -42,14 +40,21 @@ class _BarcodeScannerReturningImageState
42 height: 0.33 * MediaQuery.of(context).size.height, 40 height: 0.33 * MediaQuery.of(context).size.height,
43 child: barcode?.image != null 41 child: barcode?.image != null
44 ? Transform.rotate( 42 ? Transform.rotate(
45 - angle: 90 * pi/180, 43 + angle: 90 * pi / 180,
46 child: Image( 44 child: Image(
47 gaplessPlayback: true, 45 gaplessPlayback: true,
48 image: MemoryImage(barcode!.image!), 46 image: MemoryImage(barcode!.image!),
49 fit: BoxFit.contain, 47 fit: BoxFit.contain,
50 ), 48 ),
51 ) 49 )
52 - : Container(color: Colors.white, child: const Center(child: Text('Your scanned barcode will appear here!'))), 50 + : const ColoredBox(
  51 + color: Colors.white,
  52 + child: Center(
  53 + child: Text(
  54 + 'Your scanned barcode will appear here!',
  55 + ),
  56 + ),
  57 + ),
53 ), 58 ),
54 Container( 59 Container(
55 height: 0.66 * MediaQuery.of(context).size.height, 60 height: 0.66 * MediaQuery.of(context).size.height,
@@ -80,8 +85,10 @@ class _BarcodeScannerReturningImageState @@ -80,8 +85,10 @@ class _BarcodeScannerReturningImageState
80 child: Row( 85 child: Row(
81 mainAxisAlignment: MainAxisAlignment.spaceEvenly, 86 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
82 children: [ 87 children: [
83 - Container(  
84 - color: arguments != null && !arguments!.hasTorch ? Colors.red : Colors.white, 88 + ColoredBox(
  89 + color: arguments != null && !arguments!.hasTorch
  90 + ? Colors.red
  91 + : Colors.white,
85 child: IconButton( 92 child: IconButton(
86 // color: , 93 // color: ,
87 icon: ValueListenableBuilder( 94 icon: ValueListenableBuilder(
@@ -118,7 +125,9 @@ class _BarcodeScannerReturningImageState @@ -118,7 +125,9 @@ class _BarcodeScannerReturningImageState
118 : const Icon(Icons.play_arrow), 125 : const Icon(Icons.play_arrow),
119 iconSize: 32.0, 126 iconSize: 32.0,
120 onPressed: () => setState(() { 127 onPressed: () => setState(() {
121 - isStarted ? controller.stop() : controller.start(); 128 + isStarted
  129 + ? controller.stop()
  130 + : controller.start();
122 isStarted = !isStarted; 131 isStarted = !isStarted;
123 }), 132 }),
124 ), 133 ),
@@ -128,7 +137,8 @@ class _BarcodeScannerReturningImageState @@ -128,7 +137,8 @@ class _BarcodeScannerReturningImageState
128 height: 50, 137 height: 50,
129 child: FittedBox( 138 child: FittedBox(
130 child: Text( 139 child: Text(
131 - barcode?.barcodes.first.rawValue ?? 'Scan something!', 140 + barcode?.barcodes.first.rawValue ??
  141 + 'Scan something!',
132 overflow: TextOverflow.fade, 142 overflow: TextOverflow.fade,
133 style: Theme.of(context) 143 style: Theme.of(context)
134 .textTheme 144 .textTheme
@@ -46,7 +46,8 @@ class _BarcodeScannerWithoutControllerState @@ -46,7 +46,8 @@ class _BarcodeScannerWithoutControllerState
46 height: 50, 46 height: 50,
47 child: FittedBox( 47 child: FittedBox(
48 child: Text( 48 child: Text(
49 - capture?.barcodes.first.rawValue ?? 'Scan something!', 49 + capture?.barcodes.first.rawValue ??
  50 + 'Scan something!',
50 overflow: TextOverflow.fade, 51 overflow: TextOverflow.fade,
51 style: Theme.of(context) 52 style: Theme.of(context)
52 .textTheme 53 .textTheme
@@ -23,7 +23,8 @@ class MyHome extends StatelessWidget { @@ -23,7 +23,8 @@ class MyHome extends StatelessWidget {
23 onPressed: () { 23 onPressed: () {
24 Navigator.of(context).push( 24 Navigator.of(context).push(
25 MaterialPageRoute( 25 MaterialPageRoute(
26 - builder: (context) => const BarcodeListScannerWithController(), 26 + builder: (context) =>
  27 + const BarcodeListScannerWithController(),
27 ), 28 ),
28 ); 29 );
29 }, 30 },
@@ -10,5 +10,4 @@ class BarcodeCapture { @@ -10,5 +10,4 @@ class BarcodeCapture {
10 required this.barcodes, 10 required this.barcodes,
11 this.image, 11 this.image,
12 }); 12 });
13 -  
14 } 13 }
1 import 'package:flutter/foundation.dart'; 1 import 'package:flutter/foundation.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
  3 +import 'package:mobile_scanner/src/barcode_capture.dart';
3 import 'package:mobile_scanner/src/mobile_scanner_arguments.dart'; 4 import 'package:mobile_scanner/src/mobile_scanner_arguments.dart';
4 import 'package:mobile_scanner/src/mobile_scanner_controller.dart'; 5 import 'package:mobile_scanner/src/mobile_scanner_controller.dart';
5 -import 'package:mobile_scanner/src/barcode_capture.dart';  
6 6
7 /// A widget showing a live camera preview. 7 /// A widget showing a live camera preview.
8 class MobileScanner extends StatefulWidget { 8 class MobileScanner extends StatefulWidget {
@@ -16,8 +16,7 @@ class MobileScanner extends StatefulWidget { @@ -16,8 +16,7 @@ class MobileScanner extends StatefulWidget {
16 /// 16 ///
17 /// [barcode] The barcode object with all information about the scanned code. 17 /// [barcode] The barcode object with all information about the scanned code.
18 /// [startArguments] Information about the state of the MobileScanner widget 18 /// [startArguments] Information about the state of the MobileScanner widget
19 - final Function(  
20 - BarcodeCapture capture, MobileScannerArguments? arguments) 19 + final Function(BarcodeCapture capture, MobileScannerArguments? arguments)
21 onDetect; 20 onDetect;
22 21
23 /// Handles how the widget should fit the screen. 22 /// Handles how the widget should fit the screen.
@@ -59,7 +58,9 @@ class _MobileScannerState extends State<MobileScanner> @@ -59,7 +58,9 @@ class _MobileScannerState extends State<MobileScanner>
59 void didChangeAppLifecycleState(AppLifecycleState state) { 58 void didChangeAppLifecycleState(AppLifecycleState state) {
60 switch (state) { 59 switch (state) {
61 case AppLifecycleState.resumed: 60 case AppLifecycleState.resumed:
62 - if (!controller.isStarting && widget.autoResume && _lastState != AppLifecycleState.inactive) controller.start(); 61 + if (!controller.isStarting &&
  62 + widget.autoResume &&
  63 + _lastState != AppLifecycleState.inactive) controller.start();
63 break; 64 break;
64 case AppLifecycleState.paused: 65 case AppLifecycleState.paused:
65 case AppLifecycleState.detached: 66 case AppLifecycleState.detached:
@@ -5,7 +5,6 @@ import 'package:flutter/cupertino.dart'; @@ -5,7 +5,6 @@ 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 -import 'package:mobile_scanner/src/barcode_capture.dart';  
9 import 'package:mobile_scanner/src/barcode_utility.dart'; 8 import 'package:mobile_scanner/src/barcode_utility.dart';
10 import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; 9 import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
11 10
@@ -79,7 +78,8 @@ class MobileScannerController { @@ -79,7 +78,8 @@ class MobileScannerController {
79 late StreamSubscription events; 78 late StreamSubscription events;
80 79
81 /// A notifier that provides several arguments about the MobileScanner 80 /// A notifier that provides several arguments about the MobileScanner
82 - final ValueNotifier<MobileScannerArguments?> startArguments = ValueNotifier(null); 81 + final ValueNotifier<MobileScannerArguments?> startArguments =
  82 + ValueNotifier(null);
83 83
84 /// A notifier that provides the state of the Torch (Flash) 84 /// A notifier that provides the state of the Torch (Flash)
85 final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off); 85 final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off);
@@ -167,7 +167,8 @@ class MobileScannerController { @@ -167,7 +167,8 @@ class MobileScannerController {
167 if (startResult == null) { 167 if (startResult == null) {
168 isStarting = false; 168 isStarting = false;
169 throw MobileScannerException( 169 throw MobileScannerException(
170 - 'Failed to start mobileScanner, no response from platform side'); 170 + 'Failed to start mobileScanner, no response from platform side',
  171 + );
171 } 172 }
172 173
173 _hasTorch = startResult['torchable'] as bool? ?? false; 174 _hasTorch = startResult['torchable'] as bool? ?? false;
@@ -210,7 +211,8 @@ class MobileScannerController { @@ -210,7 +211,8 @@ class MobileScannerController {
210 Future<void> toggleTorch() async { 211 Future<void> toggleTorch() async {
211 if (_hasTorch == null) { 212 if (_hasTorch == null) {
212 throw MobileScannerException( 213 throw MobileScannerException(
213 - 'Cannot toggle torch if start() has never been called'); 214 + 'Cannot toggle torch if start() has never been called',
  215 + );
214 } else if (!_hasTorch!) { 216 } else if (!_hasTorch!) {
215 throw MobileScannerException('Device has no torch'); 217 throw MobileScannerException('Device has no torch');
216 } 218 }
@@ -272,10 +274,12 @@ class MobileScannerController { @@ -272,10 +274,12 @@ class MobileScannerController {
272 final parsed = (data as List) 274 final parsed = (data as List)
273 .map((value) => Barcode.fromNative(value as Map)) 275 .map((value) => Barcode.fromNative(value as Map))
274 .toList(); 276 .toList();
275 - _barcodesController.add(BarcodeCapture( 277 + _barcodesController.add(
  278 + BarcodeCapture(
276 barcodes: parsed, 279 barcodes: parsed,
277 image: event['image'] as Uint8List, 280 image: event['image'] as Uint8List,
278 - )); 281 + ),
  282 + );
279 break; 283 break;
280 case 'barcodeMac': 284 case 'barcodeMac':
281 _barcodesController.add( 285 _barcodesController.add(
@@ -289,11 +293,15 @@ class MobileScannerController { @@ -289,11 +293,15 @@ class MobileScannerController {
289 ); 293 );
290 break; 294 break;
291 case 'barcodeWeb': 295 case 'barcodeWeb':
292 - _barcodesController.add(BarcodeCapture(barcodes: [ 296 + _barcodesController.add(
  297 + BarcodeCapture(
  298 + barcodes: [
293 Barcode( 299 Barcode(
294 rawValue: data as String?, 300 rawValue: data as String?,
295 ) 301 )
296 - ])); 302 + ],
  303 + ),
  304 + );
297 break; 305 break;
298 case 'error': 306 case 'error':
299 throw MobileScannerException(data as String); 307 throw MobileScannerException(data as String);
@@ -12,13 +12,12 @@ dependencies: @@ -12,13 +12,12 @@ dependencies:
12 sdk: flutter 12 sdk: flutter
13 flutter_web_plugins: 13 flutter_web_plugins:
14 sdk: flutter 14 sdk: flutter
15 - json_serializable: ^6.3.1 15 + js: ^0.6.3
  16 +
16 17
17 dev_dependencies: 18 dev_dependencies:
18 - build_runner: ^2.2.0  
19 flutter_test: 19 flutter_test:
20 sdk: flutter 20 sdk: flutter
21 - json_annotation: ^4.6.0  
22 lint: ^1.10.0 21 lint: ^1.10.0
23 22
24 flutter: 23 flutter: