Showing
10 changed files
with
263 additions
and
208 deletions
| @@ -27,10 +27,11 @@ class _BarcodeScannerWithControllerState | @@ -27,10 +27,11 @@ 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) { | ||
| 31 | - return Stack( | ||
| 32 | - children: [ | ||
| 33 | - MobileScanner( | 30 | + body: Builder( |
| 31 | + builder: (context) { | ||
| 32 | + return Stack( | ||
| 33 | + children: [ | ||
| 34 | + MobileScanner( | ||
| 34 | controller: controller, | 35 | controller: controller, |
| 35 | fit: BoxFit.contain, | 36 | fit: BoxFit.contain, |
| 36 | // allowDuplicates: true, | 37 | // allowDuplicates: true, |
| @@ -42,120 +43,130 @@ class _BarcodeScannerWithControllerState | @@ -42,120 +43,130 @@ class _BarcodeScannerWithControllerState | ||
| 42 | setState(() { | 43 | setState(() { |
| 43 | this.barcode = barcode.rawValue; | 44 | this.barcode = barcode.rawValue; |
| 44 | }); | 45 | }); |
| 45 | - },), | ||
| 46 | - Align( | ||
| 47 | - alignment: Alignment.bottomCenter, | ||
| 48 | - child: Container( | 46 | + }, |
| 47 | + ), | ||
| 48 | + Align( | ||
| 49 | alignment: Alignment.bottomCenter, | 49 | alignment: Alignment.bottomCenter, |
| 50 | - height: 100, | ||
| 51 | - color: Colors.black.withOpacity(0.4), | ||
| 52 | - child: Row( | ||
| 53 | - mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| 54 | - children: [ | ||
| 55 | - IconButton( | ||
| 56 | - color: Colors.white, | ||
| 57 | - icon: ValueListenableBuilder( | ||
| 58 | - valueListenable: controller.torchState, | ||
| 59 | - builder: (context, state, child) { | ||
| 60 | - if (state == null) { | ||
| 61 | - return const Icon(Icons.flash_off, | ||
| 62 | - color: Colors.grey,); | ||
| 63 | - } | ||
| 64 | - switch (state as TorchState) { | ||
| 65 | - case TorchState.off: | ||
| 66 | - return const Icon(Icons.flash_off, | ||
| 67 | - color: Colors.grey,); | ||
| 68 | - case TorchState.on: | ||
| 69 | - return const Icon(Icons.flash_on, | ||
| 70 | - color: Colors.yellow,); | ||
| 71 | - } | ||
| 72 | - }, | 50 | + child: Container( |
| 51 | + alignment: Alignment.bottomCenter, | ||
| 52 | + height: 100, | ||
| 53 | + color: Colors.black.withOpacity(0.4), | ||
| 54 | + child: Row( | ||
| 55 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| 56 | + children: [ | ||
| 57 | + IconButton( | ||
| 58 | + color: Colors.white, | ||
| 59 | + icon: ValueListenableBuilder( | ||
| 60 | + valueListenable: controller.torchState, | ||
| 61 | + builder: (context, state, child) { | ||
| 62 | + if (state == null) { | ||
| 63 | + return const Icon( | ||
| 64 | + Icons.flash_off, | ||
| 65 | + color: Colors.grey, | ||
| 66 | + ); | ||
| 67 | + } | ||
| 68 | + switch (state as TorchState) { | ||
| 69 | + case TorchState.off: | ||
| 70 | + return const Icon( | ||
| 71 | + Icons.flash_off, | ||
| 72 | + color: Colors.grey, | ||
| 73 | + ); | ||
| 74 | + case TorchState.on: | ||
| 75 | + return const Icon( | ||
| 76 | + Icons.flash_on, | ||
| 77 | + color: Colors.yellow, | ||
| 78 | + ); | ||
| 79 | + } | ||
| 80 | + }, | ||
| 81 | + ), | ||
| 82 | + iconSize: 32.0, | ||
| 83 | + onPressed: () => controller.toggleTorch(), | ||
| 73 | ), | 84 | ), |
| 74 | - iconSize: 32.0, | ||
| 75 | - onPressed: () => controller.toggleTorch(), | ||
| 76 | - ), | ||
| 77 | - IconButton( | 85 | + IconButton( |
| 78 | color: Colors.white, | 86 | color: Colors.white, |
| 79 | icon: isStarted | 87 | icon: isStarted |
| 80 | ? const Icon(Icons.stop) | 88 | ? const Icon(Icons.stop) |
| 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(); | ||
| 87 | - isStarted = !isStarted; | ||
| 88 | - }),), | ||
| 89 | - Center( | ||
| 90 | - child: SizedBox( | ||
| 91 | - width: MediaQuery.of(context).size.width - 200, | ||
| 92 | - height: 50, | ||
| 93 | - child: FittedBox( | ||
| 94 | - child: Text( | ||
| 95 | - barcode ?? 'Scan something!', | ||
| 96 | - overflow: TextOverflow.fade, | ||
| 97 | - style: Theme.of(context) | ||
| 98 | - .textTheme | ||
| 99 | - .headline4! | ||
| 100 | - .copyWith(color: Colors.white), | 92 | + isStarted ? controller.stop() : controller.start(); |
| 93 | + isStarted = !isStarted; | ||
| 94 | + }), | ||
| 95 | + ), | ||
| 96 | + Center( | ||
| 97 | + child: SizedBox( | ||
| 98 | + width: MediaQuery.of(context).size.width - 200, | ||
| 99 | + height: 50, | ||
| 100 | + child: FittedBox( | ||
| 101 | + child: Text( | ||
| 102 | + barcode ?? 'Scan something!', | ||
| 103 | + overflow: TextOverflow.fade, | ||
| 104 | + style: Theme.of(context) | ||
| 105 | + .textTheme | ||
| 106 | + .headline4! | ||
| 107 | + .copyWith(color: Colors.white), | ||
| 108 | + ), | ||
| 101 | ), | 109 | ), |
| 102 | ), | 110 | ), |
| 103 | ), | 111 | ), |
| 104 | - ), | ||
| 105 | - IconButton( | ||
| 106 | - color: Colors.white, | ||
| 107 | - icon: ValueListenableBuilder( | ||
| 108 | - valueListenable: controller.cameraFacingState, | ||
| 109 | - builder: (context, state, child) { | ||
| 110 | - if (state == null) { | ||
| 111 | - return const Icon(Icons.camera_front); | ||
| 112 | - } | ||
| 113 | - switch (state as CameraFacing) { | ||
| 114 | - case CameraFacing.front: | 112 | + IconButton( |
| 113 | + color: Colors.white, | ||
| 114 | + icon: ValueListenableBuilder( | ||
| 115 | + valueListenable: controller.cameraFacingState, | ||
| 116 | + builder: (context, state, child) { | ||
| 117 | + if (state == null) { | ||
| 115 | return const Icon(Icons.camera_front); | 118 | return const Icon(Icons.camera_front); |
| 116 | - case CameraFacing.back: | ||
| 117 | - return const Icon(Icons.camera_rear); | 119 | + } |
| 120 | + switch (state as CameraFacing) { | ||
| 121 | + case CameraFacing.front: | ||
| 122 | + return const Icon(Icons.camera_front); | ||
| 123 | + case CameraFacing.back: | ||
| 124 | + return const Icon(Icons.camera_rear); | ||
| 125 | + } | ||
| 126 | + }, | ||
| 127 | + ), | ||
| 128 | + iconSize: 32.0, | ||
| 129 | + onPressed: () => controller.switchCamera(), | ||
| 130 | + ), | ||
| 131 | + IconButton( | ||
| 132 | + color: Colors.white, | ||
| 133 | + icon: const Icon(Icons.image), | ||
| 134 | + iconSize: 32.0, | ||
| 135 | + onPressed: () async { | ||
| 136 | + final ImagePicker _picker = ImagePicker(); | ||
| 137 | + // Pick an image | ||
| 138 | + final XFile? image = await _picker.pickImage( | ||
| 139 | + source: ImageSource.gallery, | ||
| 140 | + ); | ||
| 141 | + if (image != null) { | ||
| 142 | + if (await controller.analyzeImage(image.path)) { | ||
| 143 | + if (!mounted) return; | ||
| 144 | + ScaffoldMessenger.of(context).showSnackBar( | ||
| 145 | + const SnackBar( | ||
| 146 | + content: Text('Barcode found!'), | ||
| 147 | + backgroundColor: Colors.green, | ||
| 148 | + ), | ||
| 149 | + ); | ||
| 150 | + } else { | ||
| 151 | + if (!mounted) return; | ||
| 152 | + ScaffoldMessenger.of(context).showSnackBar( | ||
| 153 | + const SnackBar( | ||
| 154 | + content: Text('No barcode found!'), | ||
| 155 | + backgroundColor: Colors.red, | ||
| 156 | + ), | ||
| 157 | + ); | ||
| 158 | + } | ||
| 118 | } | 159 | } |
| 119 | }, | 160 | }, |
| 120 | ), | 161 | ), |
| 121 | - iconSize: 32.0, | ||
| 122 | - onPressed: () => controller.switchCamera(), | ||
| 123 | - ), | ||
| 124 | - IconButton( | ||
| 125 | - color: Colors.white, | ||
| 126 | - icon: const Icon(Icons.image), | ||
| 127 | - iconSize: 32.0, | ||
| 128 | - onPressed: () async { | ||
| 129 | - final ImagePicker _picker = ImagePicker(); | ||
| 130 | - // Pick an image | ||
| 131 | - final XFile? image = await _picker.pickImage( | ||
| 132 | - source: ImageSource.gallery,); | ||
| 133 | - if (image != null) { | ||
| 134 | - if (await controller.analyzeImage(image.path)) { | ||
| 135 | - if (!mounted) return; | ||
| 136 | - ScaffoldMessenger.of(context) | ||
| 137 | - .showSnackBar(const SnackBar( | ||
| 138 | - content: Text('Barcode found!'), | ||
| 139 | - backgroundColor: Colors.green, | ||
| 140 | - ),); | ||
| 141 | - } else { | ||
| 142 | - if (!mounted) return; | ||
| 143 | - ScaffoldMessenger.of(context) | ||
| 144 | - .showSnackBar(const SnackBar( | ||
| 145 | - content: Text('No barcode found!'), | ||
| 146 | - backgroundColor: Colors.red, | ||
| 147 | - ),); | ||
| 148 | - } | ||
| 149 | - } | ||
| 150 | - }, | ||
| 151 | - ), | ||
| 152 | - ], | 162 | + ], |
| 163 | + ), | ||
| 153 | ), | 164 | ), |
| 154 | ), | 165 | ), |
| 155 | - ), | ||
| 156 | - ], | ||
| 157 | - ); | ||
| 158 | - },), | 166 | + ], |
| 167 | + ); | ||
| 168 | + }, | ||
| 169 | + ), | ||
| 159 | ); | 170 | ); |
| 160 | } | 171 | } |
| 161 | } | 172 | } |
| @@ -18,49 +18,52 @@ class _BarcodeScannerWithoutControllerState | @@ -18,49 +18,52 @@ 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) { | ||
| 22 | - return Stack( | ||
| 23 | - children: [ | ||
| 24 | - MobileScanner( | 21 | + body: Builder( |
| 22 | + builder: (context) { | ||
| 23 | + return Stack( | ||
| 24 | + children: [ | ||
| 25 | + MobileScanner( | ||
| 25 | fit: BoxFit.contain, | 26 | fit: BoxFit.contain, |
| 26 | // allowDuplicates: false, | 27 | // allowDuplicates: false, |
| 27 | onDetect: (barcode, args) { | 28 | onDetect: (barcode, args) { |
| 28 | setState(() { | 29 | setState(() { |
| 29 | this.barcode = barcode.rawValue; | 30 | this.barcode = barcode.rawValue; |
| 30 | }); | 31 | }); |
| 31 | - },), | ||
| 32 | - Align( | ||
| 33 | - alignment: Alignment.bottomCenter, | ||
| 34 | - child: Container( | 32 | + }, |
| 33 | + ), | ||
| 34 | + Align( | ||
| 35 | alignment: Alignment.bottomCenter, | 35 | alignment: Alignment.bottomCenter, |
| 36 | - height: 100, | ||
| 37 | - color: Colors.black.withOpacity(0.4), | ||
| 38 | - child: Row( | ||
| 39 | - mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| 40 | - children: [ | ||
| 41 | - Center( | ||
| 42 | - child: SizedBox( | ||
| 43 | - width: MediaQuery.of(context).size.width - 120, | ||
| 44 | - height: 50, | ||
| 45 | - child: FittedBox( | ||
| 46 | - child: Text( | ||
| 47 | - barcode ?? 'Scan something!', | ||
| 48 | - overflow: TextOverflow.fade, | ||
| 49 | - style: Theme.of(context) | ||
| 50 | - .textTheme | ||
| 51 | - .headline4! | ||
| 52 | - .copyWith(color: Colors.white), | 36 | + child: Container( |
| 37 | + alignment: Alignment.bottomCenter, | ||
| 38 | + height: 100, | ||
| 39 | + color: Colors.black.withOpacity(0.4), | ||
| 40 | + child: Row( | ||
| 41 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| 42 | + children: [ | ||
| 43 | + Center( | ||
| 44 | + child: SizedBox( | ||
| 45 | + width: MediaQuery.of(context).size.width - 120, | ||
| 46 | + height: 50, | ||
| 47 | + child: FittedBox( | ||
| 48 | + child: Text( | ||
| 49 | + barcode ?? 'Scan something!', | ||
| 50 | + overflow: TextOverflow.fade, | ||
| 51 | + style: Theme.of(context) | ||
| 52 | + .textTheme | ||
| 53 | + .headline4! | ||
| 54 | + .copyWith(color: Colors.white), | ||
| 55 | + ), | ||
| 53 | ), | 56 | ), |
| 54 | ), | 57 | ), |
| 55 | ), | 58 | ), |
| 56 | - ), | ||
| 57 | - ], | 59 | + ], |
| 60 | + ), | ||
| 58 | ), | 61 | ), |
| 59 | ), | 62 | ), |
| 60 | - ), | ||
| 61 | - ], | ||
| 62 | - ); | ||
| 63 | - },), | 63 | + ], |
| 64 | + ); | ||
| 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( | ||
| 23 | - builder: (context) => const BarcodeScannerWithController(), | ||
| 24 | - ),); | 22 | + Navigator.of(context).push( |
| 23 | + MaterialPageRoute( | ||
| 24 | + builder: (context) => const BarcodeScannerWithController(), | ||
| 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 | ), |
| @@ -14,13 +14,15 @@ import 'package:mobile_scanner/src/web/media.dart'; | @@ -14,13 +14,15 @@ import 'package:mobile_scanner/src/web/media.dart'; | ||
| 14 | class MobileScannerWebPlugin { | 14 | class MobileScannerWebPlugin { |
| 15 | static void registerWith(Registrar registrar) { | 15 | static void registerWith(Registrar registrar) { |
| 16 | final PluginEventChannel event = PluginEventChannel( | 16 | final PluginEventChannel event = PluginEventChannel( |
| 17 | - 'dev.steenbakker.mobile_scanner/scanner/event', | ||
| 18 | - const StandardMethodCodec(), | ||
| 19 | - registrar,); | 17 | + 'dev.steenbakker.mobile_scanner/scanner/event', |
| 18 | + const StandardMethodCodec(), | ||
| 19 | + registrar, | ||
| 20 | + ); | ||
| 20 | final MethodChannel channel = MethodChannel( | 21 | final MethodChannel channel = MethodChannel( |
| 21 | - 'dev.steenbakker.mobile_scanner/scanner/method', | ||
| 22 | - const StandardMethodCodec(), | ||
| 23 | - registrar,); | 22 | + 'dev.steenbakker.mobile_scanner/scanner/method', |
| 23 | + const StandardMethodCodec(), | ||
| 24 | + registrar, | ||
| 25 | + ); | ||
| 24 | final MobileScannerWebPlugin instance = MobileScannerWebPlugin(); | 26 | final MobileScannerWebPlugin instance = MobileScannerWebPlugin(); |
| 25 | WidgetsFlutterBinding.ensureInitialized(); | 27 | WidgetsFlutterBinding.ensureInitialized(); |
| 26 | 28 | ||
| @@ -57,9 +59,10 @@ class MobileScannerWebPlugin { | @@ -57,9 +59,10 @@ class MobileScannerWebPlugin { | ||
| 57 | return cancel(); | 59 | return cancel(); |
| 58 | default: | 60 | default: |
| 59 | throw PlatformException( | 61 | throw PlatformException( |
| 60 | - code: 'Unimplemented', | ||
| 61 | - details: "The mobile_scanner plugin for web doesn't implement " | ||
| 62 | - "the method '${call.method}'",); | 62 | + code: 'Unimplemented', |
| 63 | + details: "The mobile_scanner plugin for web doesn't implement " | ||
| 64 | + "the method '${call.method}'", | ||
| 65 | + ); | ||
| 63 | } | 66 | } |
| 64 | } | 67 | } |
| 65 | 68 | ||
| @@ -87,10 +90,11 @@ class MobileScannerWebPlugin { | @@ -87,10 +90,11 @@ class MobileScannerWebPlugin { | ||
| 87 | // See https://github.com/flutter/flutter/issues/41563 | 90 | // See https://github.com/flutter/flutter/issues/41563 |
| 88 | // ignore: UNDEFINED_PREFIXED_NAME, avoid_dynamic_calls | 91 | // ignore: UNDEFINED_PREFIXED_NAME, avoid_dynamic_calls |
| 89 | ui.platformViewRegistry.registerViewFactory( | 92 | ui.platformViewRegistry.registerViewFactory( |
| 90 | - viewID, | ||
| 91 | - (int id) => vidDiv | ||
| 92 | - ..style.width = '100%' | ||
| 93 | - ..style.height = '100%',); | 93 | + viewID, |
| 94 | + (int id) => vidDiv | ||
| 95 | + ..style.width = '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) { |
| @@ -108,8 +112,9 @@ class MobileScannerWebPlugin { | @@ -108,8 +112,9 @@ class MobileScannerWebPlugin { | ||
| 108 | if (capabilities != null && capabilities['facingMode'] as bool) { | 112 | if (capabilities != null && capabilities['facingMode'] as bool) { |
| 109 | final constraints = { | 113 | final constraints = { |
| 110 | 'video': VideoOptions( | 114 | 'video': VideoOptions( |
| 111 | - facingMode: | ||
| 112 | - cameraFacing == CameraFacing.front ? 'user' : 'environment',) | 115 | + facingMode: |
| 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, | ||
| 33 | - this.onDetect, | ||
| 34 | - this.controller, | ||
| 35 | - this.fit = BoxFit.cover, | ||
| 36 | - this.allowDuplicates = false, }) | ||
| 37 | - : super(key: key); | 31 | + const MobileScanner({ |
| 32 | + Key? key, | ||
| 33 | + this.onDetect, | ||
| 34 | + this.controller, | ||
| 35 | + this.fit = BoxFit.cover, | ||
| 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,8 +69,9 @@ class _MobileScannerState extends State<MobileScanner> | @@ -69,8 +69,9 @@ 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) { | ||
| 73 | - return ValueListenableBuilder( | 72 | + return LayoutBuilder( |
| 73 | + builder: (context, BoxConstraints constraints) { | ||
| 74 | + return ValueListenableBuilder( | ||
| 74 | valueListenable: controller.args, | 75 | valueListenable: controller.args, |
| 75 | builder: (context, value, child) { | 76 | builder: (context, value, child) { |
| 76 | value = value as MobileScannerArguments?; | 77 | value = value as MobileScannerArguments?; |
| @@ -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, | ||
| 60 | - this.ratio, | ||
| 61 | - this.torchEnabled, | ||
| 62 | - this.formats, }) { | 58 | + MobileScannerController({ |
| 59 | + this.facing = CameraFacing.back, | ||
| 60 | + this.ratio, | ||
| 61 | + this.torchEnabled, | ||
| 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; |
| @@ -182,14 +190,19 @@ class MobileScannerController { | @@ -182,14 +190,19 @@ class MobileScannerController { | ||
| 182 | 190 | ||
| 183 | if (kIsWeb) { | 191 | if (kIsWeb) { |
| 184 | args.value = MobileScannerArguments( | 192 | args.value = MobileScannerArguments( |
| 185 | - webId: startResult['ViewID'] as String?, | ||
| 186 | - size: Size(startResult['videoWidth'] as double, startResult['videoHeight'] as double), | ||
| 187 | - hasTorch: hasTorch,); | 193 | + webId: startResult['ViewID'] as String?, |
| 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, | ||
| 191 | - size: toSize(startResult['size'] as Map<String, double>), | ||
| 192 | - hasTorch: hasTorch,); | 202 | + textureId: startResult['textureId'] as int, |
| 203 | + size: toSize(startResult['size'] as Map<String, double>), | ||
| 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,21 +63,22 @@ class Barcode { | @@ -63,21 +63,22 @@ 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, | ||
| 68 | - this.format = BarcodeFormat.ean13, | ||
| 69 | - this.rawBytes, | ||
| 70 | - this.type = BarcodeType.text, | ||
| 71 | - this.calendarEvent, | ||
| 72 | - this.contactInfo, | ||
| 73 | - this.driverLicense, | ||
| 74 | - this.email, | ||
| 75 | - this.geoPoint, | ||
| 76 | - this.phone, | ||
| 77 | - this.sms, | ||
| 78 | - this.url, | ||
| 79 | - this.wifi, | ||
| 80 | - required this.rawValue, }); | 66 | + Barcode({ |
| 67 | + this.corners, | ||
| 68 | + this.format = BarcodeFormat.ean13, | ||
| 69 | + this.rawBytes, | ||
| 70 | + this.type = BarcodeType.text, | ||
| 71 | + this.calendarEvent, | ||
| 72 | + this.contactInfo, | ||
| 73 | + this.driverLicense, | ||
| 74 | + this.email, | ||
| 75 | + this.geoPoint, | ||
| 76 | + this.phone, | ||
| 77 | + this.sms, | ||
| 78 | + this.url, | ||
| 79 | + this.wifi, | ||
| 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() |
-
Please register or login to post a comment