Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/widgets/data_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class DataScannerConfiguration<T> {
/// Whether to show the torch toggle. Defaults to `false`.
final bool showTorchToggle;

/// Whether to rotate the camera preview on Android. Defaults to `false`. Consider this a workaround!
final bool rotateOnAndroid;

/// Where to position the torch toggle. Defaults to [Alignment.bottomCenter]
final Alignment torchToggleAlignment;

Expand Down Expand Up @@ -100,6 +103,7 @@ class DataScannerConfiguration<T> {
this.torchToggleAlignment = Alignment.bottomCenter,
this.torchToggleMargin = const EdgeInsets.all(32),
this.detectionOutline,
this.rotateOnAndroid = false,
RouteObserver<ModalRoute>? routeObserver,
}) : _routeObserver = routeObserver ?? RouteObserver();
}
Expand Down Expand Up @@ -387,6 +391,7 @@ class _DataScannerState<T> extends State<DataScanner> with RouteAware {
SizedCameraPreview(
size: _calculatedSize!,
cameraController: cameraController,
rotateOnAndroid: scannerConfiguration.rotateOnAndroid,
),
if (scannerConfiguration.showOverlay)
CameraOverlay(
Expand Down
6 changes: 5 additions & 1 deletion lib/widgets/sized_camera_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:flutter/material.dart';

/// Sized and scaled [CameraPreview] wrapper.
class SizedCameraPreview<T> extends StatefulWidget {
/// temporary Workaround: rotate Camera Preview on Android Devices
final bool rotateOnAndroid;

/// Size of the clipped preview.
final Size size;

Expand All @@ -15,6 +18,7 @@ class SizedCameraPreview<T> extends StatefulWidget {
Key? key,
required this.size,
required this.cameraController,
this.rotateOnAndroid = false,
}) : super(key: key);

@override
Expand Down Expand Up @@ -48,7 +52,7 @@ class _SizedCameraPreviewState<T> extends State<SizedCameraPreview> {
}

Widget _rotatedOnAndroid(Widget content) {
if (Platform.isAndroid) {
if (widget.rotateOnAndroid && Platform.isAndroid) {
return RotatedBox(
quarterTurns: 1,
child: content,
Expand Down