Showing
1 changed file
with
11 additions
and
26 deletions
| @@ -12,37 +12,24 @@ class BarcodeScannerWithScanWindow extends StatefulWidget { | @@ -12,37 +12,24 @@ class BarcodeScannerWithScanWindow extends StatefulWidget { | ||
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | class _BarcodeScannerWithScanWindowState | 14 | class _BarcodeScannerWithScanWindowState |
| 15 | - extends State<BarcodeScannerWithScanWindow> | ||
| 16 | - with SingleTickerProviderStateMixin { | ||
| 17 | - String? barcode; | ||
| 18 | - | ||
| 19 | - late Rect scanWindow; | 15 | + extends State<BarcodeScannerWithScanWindow> { |
| 20 | late MobileScannerController controller; | 16 | late MobileScannerController controller; |
| 17 | + String? barcode; | ||
| 21 | 18 | ||
| 22 | @override | 19 | @override |
| 23 | void initState() { | 20 | void initState() { |
| 24 | super.initState(); | 21 | super.initState(); |
| 22 | + controller = MobileScannerController(); | ||
| 23 | + } | ||
| 25 | 24 | ||
| 26 | - final screenWidth = | ||
| 27 | - window.physicalSize.shortestSide / window.devicePixelRatio; | ||
| 28 | - final screenHeight = | ||
| 29 | - window.physicalSize.longestSide / window.devicePixelRatio; | ||
| 30 | - | ||
| 31 | - scanWindow = Rect.fromCenter( | ||
| 32 | - center: Offset(screenWidth / 2, screenHeight / 2), | 25 | + @override |
| 26 | + Widget build(BuildContext context) { | ||
| 27 | + final scanWindow = Rect.fromCenter( | ||
| 28 | + center: MediaQuery.of(context).size.center(Offset.zero), | ||
| 33 | width: 200, | 29 | width: 200, |
| 34 | height: 200, | 30 | height: 200, |
| 35 | ); | 31 | ); |
| 36 | 32 | ||
| 37 | - controller = MobileScannerController( | ||
| 38 | - torchEnabled: false, | ||
| 39 | - ); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - bool isStarted = true; | ||
| 43 | - | ||
| 44 | - @override | ||
| 45 | - Widget build(BuildContext context) { | ||
| 46 | return Scaffold( | 33 | return Scaffold( |
| 47 | backgroundColor: Colors.black, | 34 | backgroundColor: Colors.black, |
| 48 | body: Builder( | 35 | body: Builder( |
| @@ -52,11 +39,9 @@ class _BarcodeScannerWithScanWindowState | @@ -52,11 +39,9 @@ class _BarcodeScannerWithScanWindowState | ||
| 52 | MobileScanner( | 39 | MobileScanner( |
| 53 | scanWindow: scanWindow, | 40 | scanWindow: scanWindow, |
| 54 | controller: controller, | 41 | controller: controller, |
| 55 | - onDetect: (barcode, args) { | ||
| 56 | - setState(() { | ||
| 57 | - this.barcode = barcode.rawValue; | ||
| 58 | - }); | ||
| 59 | - }, | 42 | + onDetect: (barcode, _) => setState(() { |
| 43 | + this.barcode = barcode.rawValue; | ||
| 44 | + }), | ||
| 60 | ), | 45 | ), |
| 61 | CustomPaint( | 46 | CustomPaint( |
| 62 | painter: ScannerOverlay(scanWindow), | 47 | painter: ScannerOverlay(scanWindow), |
-
Please register or login to post a comment