Showing
4 changed files
with
32 additions
and
39 deletions
| @@ -16,10 +16,10 @@ class _BarcodeScannerWithControllerState | @@ -16,10 +16,10 @@ class _BarcodeScannerWithControllerState | ||
| 16 | String? barcode; | 16 | String? barcode; |
| 17 | 17 | ||
| 18 | MobileScannerController controller = MobileScannerController( | 18 | MobileScannerController controller = MobileScannerController( |
| 19 | - torchEnabled: true, | ||
| 20 | - // formats: [BarcodeFormat.qrCode] | ||
| 21 | - // facing: CameraFacing.front, | ||
| 22 | - ); | 19 | + torchEnabled: true, |
| 20 | + // formats: [BarcodeFormat.qrCode] | ||
| 21 | + // facing: CameraFacing.front, | ||
| 22 | + ); | ||
| 23 | 23 | ||
| 24 | bool isStarted = true; | 24 | bool isStarted = true; |
| 25 | 25 |
| @@ -60,41 +60,36 @@ class _MobileScannerState extends State<MobileScanner> | @@ -60,41 +60,36 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 60 | 60 | ||
| 61 | @override | 61 | @override |
| 62 | Widget build(BuildContext context) { | 62 | Widget build(BuildContext context) { |
| 63 | - return LayoutBuilder(builder: (context, BoxConstraints constraints) { | ||
| 64 | - return ValueListenableBuilder( | ||
| 65 | - valueListenable: controller.args, | ||
| 66 | - builder: (context, value, child) { | ||
| 67 | - value = value as MobileScannerArguments?; | ||
| 68 | - if (value == null) { | ||
| 69 | - return Container(color: Colors.black); | ||
| 70 | - } else { | ||
| 71 | - controller.barcodes.listen( | ||
| 72 | - (a) => | ||
| 73 | - widget.onDetect!(a, value as MobileScannerArguments)); | ||
| 74 | - return ClipRect( | ||
| 75 | - child: SizedBox( | ||
| 76 | - width: MediaQuery | ||
| 77 | - .of(context) | ||
| 78 | - .size | ||
| 79 | - .width, | ||
| 80 | - height: MediaQuery | ||
| 81 | - .of(context) | ||
| 82 | - .size | ||
| 83 | - .height, | ||
| 84 | - child: FittedBox( | ||
| 85 | - fit: widget.fit, | ||
| 86 | - child: SizedBox( | ||
| 87 | - width: value.size.width, | ||
| 88 | - height: value.size.height, | ||
| 89 | - child: kIsWeb ? HtmlElementView(viewType: value.webId!) : Texture(textureId: value.textureId!), | ||
| 90 | - ), | 63 | + return LayoutBuilder(builder: (context, BoxConstraints constraints) { |
| 64 | + return ValueListenableBuilder( | ||
| 65 | + valueListenable: controller.args, | ||
| 66 | + builder: (context, value, child) { | ||
| 67 | + value = value as MobileScannerArguments?; | ||
| 68 | + if (value == null) { | ||
| 69 | + return Container(color: Colors.black); | ||
| 70 | + } else { | ||
| 71 | + controller.barcodes.listen( | ||
| 72 | + (a) => widget.onDetect!(a, value as MobileScannerArguments)); | ||
| 73 | + return ClipRect( | ||
| 74 | + child: SizedBox( | ||
| 75 | + width: MediaQuery.of(context).size.width, | ||
| 76 | + height: MediaQuery.of(context).size.height, | ||
| 77 | + child: FittedBox( | ||
| 78 | + fit: widget.fit, | ||
| 79 | + child: SizedBox( | ||
| 80 | + width: value.size.width, | ||
| 81 | + height: value.size.height, | ||
| 82 | + child: kIsWeb | ||
| 83 | + ? HtmlElementView(viewType: value.webId!) | ||
| 84 | + : Texture(textureId: value.textureId!), | ||
| 91 | ), | 85 | ), |
| 92 | ), | 86 | ), |
| 93 | - ); | ||
| 94 | - } | ||
| 95 | - }); | ||
| 96 | - }); | ||
| 97 | - } | 87 | + ), |
| 88 | + ); | ||
| 89 | + } | ||
| 90 | + }); | ||
| 91 | + }); | ||
| 92 | + } | ||
| 98 | 93 | ||
| 99 | @override | 94 | @override |
| 100 | void didUpdateWidget(covariant MobileScanner oldWidget) { | 95 | void didUpdateWidget(covariant MobileScanner oldWidget) { |
| @@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart'; | @@ -6,7 +6,6 @@ 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 | 8 | ||
| 9 | -import 'mobile_scanner_arguments.dart'; | ||
| 10 | import 'objects/barcode_utility.dart'; | 9 | import 'objects/barcode_utility.dart'; |
| 11 | 10 | ||
| 12 | /// The facing of a camera. | 11 | /// The facing of a camera. |
| @@ -188,7 +187,6 @@ class MobileScannerController { | @@ -188,7 +187,6 @@ class MobileScannerController { | ||
| 188 | size: Size(startResult['videoWidth'], startResult['videoHeight']), | 187 | size: Size(startResult['videoWidth'], startResult['videoHeight']), |
| 189 | hasTorch: hasTorch); | 188 | hasTorch: hasTorch); |
| 190 | } else { | 189 | } else { |
| 191 | - | ||
| 192 | args.value = MobileScannerArguments( | 190 | args.value = MobileScannerArguments( |
| 193 | textureId: startResult['textureId'], | 191 | textureId: startResult['textureId'], |
| 194 | size: toSize(startResult['size']), | 192 | size: toSize(startResult['size']), |
-
Please register or login to post a comment