Skip to content

Commit a13cb73

Browse files
mjl0602AlexV525
authored andcommitted
add CameraPreview quarterTurns paramater
1 parent 8a9a0cf commit a13cb73

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CameraPicker extends StatefulWidget {
3434
this.maximumRecordingDuration = const Duration(seconds: 15),
3535
this.theme,
3636
this.resolutionPreset = ResolutionPreset.max,
37+
this.quarterTurns = 0,
3738
CameraPickerTextDelegate textDelegate,
3839
}) : assert(
3940
isAllowRecording == true || isOnlyAllowRecording != true,
@@ -50,6 +51,10 @@ class CameraPicker extends StatefulWidget {
5051
: DefaultCameraPickerTextDelegate());
5152
}
5253

54+
/// Quarter rotate turns.
55+
/// 摄像机视图旋转次数
56+
final int quarterTurns;
57+
5358
/// Whether the picker can record video.
5459
/// 选择器是否可以录像
5560
final bool isAllowRecording;
@@ -81,6 +86,7 @@ class CameraPicker extends StatefulWidget {
8186
bool isOnlyAllowRecording = false,
8287
Duration maximumRecordingDuration = const Duration(seconds: 15),
8388
ThemeData theme,
89+
int cameraQuarterTurns = 0,
8490
CameraPickerTextDelegate textDelegate,
8591
ResolutionPreset resolutionPreset = ResolutionPreset.max,
8692
}) async {
@@ -99,6 +105,7 @@ class CameraPicker extends StatefulWidget {
99105
isAllowRecording: isAllowRecording,
100106
isOnlyAllowRecording: isOnlyAllowRecording,
101107
theme: theme,
108+
quarterTurns: cameraQuarterTurns,
102109
textDelegate: textDelegate,
103110
resolutionPreset: resolutionPreset,
104111
),
@@ -533,8 +540,7 @@ class CameraPickerState extends State<CameraPicker> {
533540
children: <Widget>[
534541
const Spacer(),
535542
// TODO(Alex): There's an issue tracking NPE of the camera plugin, so switching is temporary disabled .
536-
if ((cameras?.length ?? 0) > 1)
537-
switchCamerasButton,
543+
if ((cameras?.length ?? 0) > 1) switchCamerasButton,
538544
],
539545
),
540546
);
@@ -683,9 +689,12 @@ class CameraPickerState extends State<CameraPicker> {
683689
children: <Widget>[
684690
if (isInitialized)
685691
Center(
686-
child: AspectRatio(
687-
aspectRatio: cameraController.value.aspectRatio,
688-
child: CameraPreview(cameraController),
692+
child: RotatedBox(
693+
quarterTurns: widget.quarterTurns ?? 0,
694+
child: AspectRatio(
695+
aspectRatio: cameraController.value.aspectRatio,
696+
child: CameraPreview(cameraController),
697+
),
689698
),
690699
)
691700
else

0 commit comments

Comments
 (0)