Browse Source

allow to set camera lens direction

pull/89/head
Khoren Markosyan 2 years ago
parent
commit
9eba130c9f
  1. 1
      example/lib/main.dart
  2. 2
      lib/flutter_zxing.dart
  3. 10
      lib/src/ui/reader_widget.dart

1
example/lib/main.dart

@ -89,6 +89,7 @@ class _DemoPageState extends State<DemoPage> {
isMultiScan: isMultiScan, isMultiScan: isMultiScan,
scanDelay: Duration(milliseconds: isMultiScan ? 50 : 500), scanDelay: Duration(milliseconds: isMultiScan ? 50 : 500),
resolution: ResolutionPreset.high, resolution: ResolutionPreset.high,
lensDirection: CameraLensDirection.back,
), ),
if (showDebugInfo) if (showDebugInfo)
DebugInfoWidget( DebugInfoWidget(

2
lib/flutter_zxing.dart

@ -7,7 +7,7 @@ import 'zxing_cross.dart'
if (dart.library.io) 'zxing_mobile.dart' if (dart.library.io) 'zxing_mobile.dart'
if (dart.library.html) 'zxing_web.dart'; if (dart.library.html) 'zxing_web.dart';
export 'package:camera/camera.dart' show ResolutionPreset; export 'package:camera/camera.dart' show ResolutionPreset, CameraLensDirection;
export 'src/models/models.dart'; export 'src/models/models.dart';
export 'src/ui/ui.dart'; export 'src/ui/ui.dart';

10
lib/src/ui/reader_widget.dart

@ -37,6 +37,7 @@ class ReaderWidget extends StatefulWidget {
this.scanDelaySuccess = const Duration(milliseconds: 1000), this.scanDelaySuccess = const Duration(milliseconds: 1000),
this.cropPercent = 0.5, // 50% of the screen this.cropPercent = 0.5, // 50% of the screen
this.resolution = ResolutionPreset.high, this.resolution = ResolutionPreset.high,
this.lensDirection = CameraLensDirection.back,
this.loading = this.loading =
const DecoratedBox(decoration: BoxDecoration(color: Colors.black)), const DecoratedBox(decoration: BoxDecoration(color: Colors.black)),
}); });
@ -111,6 +112,9 @@ class ReaderWidget extends StatefulWidget {
/// Camera resolution /// Camera resolution
final ResolutionPreset resolution; final ResolutionPreset resolution;
/// Camera lens direction
final CameraLensDirection lensDirection;
/// Delay between scans when a code is detected, will be ignored if isMultiScan is true /// Delay between scans when a code is detected, will be ignored if isMultiScan is true
final Duration scanDelaySuccess; final Duration scanDelaySuccess;
@ -158,7 +162,11 @@ class _ReaderWidgetState extends State<ReaderWidget>
setState(() { setState(() {
this.cameras = cameras; this.cameras = cameras;
if (cameras.isNotEmpty) { if (cameras.isNotEmpty) {
selectedCamera = cameras.first; selectedCamera = cameras.firstWhere(
(CameraDescription camera) =>
camera.lensDirection == widget.lensDirection,
orElse: () => cameras.first,
);
onNewCameraSelected(selectedCamera); onNewCameraSelected(selectedCamera);
} }
}); });

Loading…
Cancel
Save