|
|
@ -18,7 +18,8 @@ class ReaderWidget extends StatefulWidget { |
|
|
|
this.codeFormat = Format.Any, |
|
|
|
this.codeFormat = Format.Any, |
|
|
|
this.beep = true, |
|
|
|
this.beep = true, |
|
|
|
this.showCroppingRect = true, |
|
|
|
this.showCroppingRect = true, |
|
|
|
this.scanDelay = const Duration(milliseconds: 500), // 500ms delay |
|
|
|
this.showFlashlight = true, |
|
|
|
|
|
|
|
this.scanDelay = const Duration(milliseconds: 1000), // 1000ms delay |
|
|
|
this.cropPercent = 0.5, // 50% of the screen |
|
|
|
this.cropPercent = 0.5, // 50% of the screen |
|
|
|
this.resolution = ResolutionPreset.high, |
|
|
|
this.resolution = ResolutionPreset.high, |
|
|
|
}) : super(key: key); |
|
|
|
}) : super(key: key); |
|
|
@ -28,6 +29,7 @@ class ReaderWidget extends StatefulWidget { |
|
|
|
final int codeFormat; |
|
|
|
final int codeFormat; |
|
|
|
final bool beep; |
|
|
|
final bool beep; |
|
|
|
final bool showCroppingRect; |
|
|
|
final bool showCroppingRect; |
|
|
|
|
|
|
|
final bool showFlashlight; |
|
|
|
final Duration scanDelay; |
|
|
|
final Duration scanDelay; |
|
|
|
final double cropPercent; |
|
|
|
final double cropPercent; |
|
|
|
final ResolutionPreset resolution; |
|
|
|
final ResolutionPreset resolution; |
|
|
@ -112,6 +114,7 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
await controller?.initialize(); |
|
|
|
await controller?.initialize(); |
|
|
|
|
|
|
|
await controller?.setFlashMode(FlashMode.off); |
|
|
|
controller?.startImageStream(processCameraImage); |
|
|
|
controller?.startImageStream(processCameraImage); |
|
|
|
} on CameraException catch (e) { |
|
|
|
} on CameraException catch (e) { |
|
|
|
debugPrint('${e.code}: ${e.description}'); |
|
|
|
debugPrint('${e.code}: ${e.description}'); |
|
|
@ -202,8 +205,8 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
widget.showCroppingRect |
|
|
|
if (widget.showCroppingRect) |
|
|
|
? Container( |
|
|
|
Container( |
|
|
|
decoration: ShapeDecoration( |
|
|
|
decoration: ShapeDecoration( |
|
|
|
shape: ScannerOverlay( |
|
|
|
shape: ScannerOverlay( |
|
|
|
borderColor: Theme.of(context).primaryColor, |
|
|
|
borderColor: Theme.of(context).primaryColor, |
|
|
@ -214,10 +217,45 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
cutOutSize: cropSize, |
|
|
|
cutOutSize: cropSize, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
if (widget.showFlashlight) |
|
|
|
|
|
|
|
Positioned( |
|
|
|
|
|
|
|
top: 20, |
|
|
|
|
|
|
|
left: 20, |
|
|
|
|
|
|
|
child: FloatingActionButton( |
|
|
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
|
|
FlashMode mode = cameraController.value.flashMode; |
|
|
|
|
|
|
|
switch (mode) { |
|
|
|
|
|
|
|
case FlashMode.torch: |
|
|
|
|
|
|
|
mode = FlashMode.off; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FlashMode.off: |
|
|
|
|
|
|
|
mode = FlashMode.torch; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cameraController.setFlashMode(mode); |
|
|
|
|
|
|
|
setState(() {}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
mini: true, |
|
|
|
|
|
|
|
backgroundColor: Colors.black26, |
|
|
|
|
|
|
|
child: Icon(_flashIcon(cameraController)), |
|
|
|
|
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
: Container() |
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IconData _flashIcon(CameraController cameraController) { |
|
|
|
|
|
|
|
final FlashMode mode = cameraController.value.flashMode; |
|
|
|
|
|
|
|
switch (mode) { |
|
|
|
|
|
|
|
case FlashMode.torch: |
|
|
|
|
|
|
|
return Icons.flash_on; |
|
|
|
|
|
|
|
case FlashMode.off: |
|
|
|
|
|
|
|
return Icons.flash_off; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return Icons.flash_off; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|