|
|
@ -126,27 +126,27 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
List<CameraDescription> cameras = <CameraDescription>[]; |
|
|
|
List<CameraDescription> cameras = <CameraDescription>[]; |
|
|
|
CameraDescription? selectedCamera; |
|
|
|
CameraDescription? selectedCamera; |
|
|
|
CameraController? controller; |
|
|
|
CameraController? controller; |
|
|
|
bool _cameraOn = false; |
|
|
|
|
|
|
|
|
|
|
|
// true when code detecting is ongoing |
|
|
|
|
|
|
|
bool _isProcessing = false; |
|
|
|
|
|
|
|
bool _isCameraOn = false; |
|
|
|
|
|
|
|
bool _isFlashAvailable = true; |
|
|
|
|
|
|
|
bool _isMultiScan = false; |
|
|
|
|
|
|
|
|
|
|
|
double _zoom = 1.0; |
|
|
|
double _zoom = 1.0; |
|
|
|
double _scaleFactor = 1.0; |
|
|
|
double _scaleFactor = 1.0; |
|
|
|
double _maxZoomLevel = 1.0; |
|
|
|
double _maxZoomLevel = 1.0; |
|
|
|
double _minZoomLevel = 1.0; |
|
|
|
double _minZoomLevel = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// true when code detecting is ongoing |
|
|
|
|
|
|
|
bool _isProcessing = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isMultiScan = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Codes results = Codes(); |
|
|
|
Codes results = Codes(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
super.initState(); |
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
isMultiScan = widget.isMultiScan; |
|
|
|
_isMultiScan = widget.isMultiScan; |
|
|
|
initStateAsync(); |
|
|
|
initStateAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -174,7 +174,7 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
|
|
|
|
|
|
|
|
switch (state) { |
|
|
|
switch (state) { |
|
|
|
case AppLifecycleState.resumed: |
|
|
|
case AppLifecycleState.resumed: |
|
|
|
if (cameras.isNotEmpty && !_cameraOn) { |
|
|
|
if (cameras.isNotEmpty && !_isCameraOn) { |
|
|
|
onNewCameraSelected(cameras.first); |
|
|
|
onNewCameraSelected(cameras.first); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -182,7 +182,7 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
case AppLifecycleState.paused: |
|
|
|
case AppLifecycleState.paused: |
|
|
|
controller?.dispose(); |
|
|
|
controller?.dispose(); |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
_cameraOn = false; |
|
|
|
_isCameraOn = false; |
|
|
|
}); |
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case AppLifecycleState.detached: |
|
|
|
case AppLifecycleState.detached: |
|
|
@ -202,7 +202,7 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
void rebuildOnMount() { |
|
|
|
void rebuildOnMount() { |
|
|
|
if (mounted) { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
_cameraOn = true; |
|
|
|
_isCameraOn = true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -239,6 +239,7 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
try { |
|
|
|
try { |
|
|
|
await cameraController.setFlashMode(FlashMode.off); |
|
|
|
await cameraController.setFlashMode(FlashMode.off); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
_isFlashAvailable = false; |
|
|
|
debugPrint('Error: $e'); |
|
|
|
debugPrint('Error: $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -316,7 +317,7 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
final bool isCameraReady = cameras.isNotEmpty && |
|
|
|
final bool isCameraReady = cameras.isNotEmpty && |
|
|
|
_cameraOn && |
|
|
|
_isCameraOn && |
|
|
|
controller != null && |
|
|
|
controller != null && |
|
|
|
controller!.value.isInitialized; |
|
|
|
controller!.value.isInitialized; |
|
|
|
final Size size = MediaQuery.of(context).size; |
|
|
|
final Size size = MediaQuery.of(context).size; |
|
|
@ -389,7 +390,9 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
child: Row( |
|
|
|
child: Row( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
children: <Widget>[ |
|
|
|
children: <Widget>[ |
|
|
|
if (widget.showFlashlight && isCameraReady) |
|
|
|
if (widget.showFlashlight && |
|
|
|
|
|
|
|
isCameraReady && |
|
|
|
|
|
|
|
_isFlashAvailable) |
|
|
|
IconButton( |
|
|
|
IconButton( |
|
|
|
onPressed: _onFlashButtonTapped, |
|
|
|
onPressed: _onFlashButtonTapped, |
|
|
|
color: Colors.white, |
|
|
|
color: Colors.white, |
|
|
@ -420,12 +423,12 @@ class _ReaderWidgetState extends State<ReaderWidget> |
|
|
|
if (widget.onMultiScanModeChanged != null) |
|
|
|
if (widget.onMultiScanModeChanged != null) |
|
|
|
SafeArea( |
|
|
|
SafeArea( |
|
|
|
child: ScanModeDropdown( |
|
|
|
child: ScanModeDropdown( |
|
|
|
isMultiScan: isMultiScan, |
|
|
|
isMultiScan: _isMultiScan, |
|
|
|
alignment: widget.multiScanModeAlignment, |
|
|
|
alignment: widget.multiScanModeAlignment, |
|
|
|
padding: widget.multiScanModePadding, |
|
|
|
padding: widget.multiScanModePadding, |
|
|
|
onChanged: (bool value) { |
|
|
|
onChanged: (bool value) { |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
isMultiScan = value; |
|
|
|
_isMultiScan = value; |
|
|
|
}); |
|
|
|
}); |
|
|
|
widget.onMultiScanModeChanged?.call(value); |
|
|
|
widget.onMultiScanModeChanged?.call(value); |
|
|
|
}, |
|
|
|
}, |
|
|
|