Skip to content

Commit 103562b

Browse files
authored
🔥 Remove shouldLockPortrait (#49)
1 parent 7162d31 commit 103562b

File tree

2 files changed

+5
-54
lines changed

2 files changed

+5
-54
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class CameraPicker extends StatefulWidget {
3737
this.enablePinchToZoom = true,
3838
this.enablePullToZoomInRecord = true,
3939
this.shouldDeletePreviewFile = false,
40-
this.shouldLockPortrait = true,
4140
this.maximumRecordingDuration = const Duration(seconds: 15),
4241
this.theme,
4342
this.resolutionPreset = ResolutionPreset.max,
@@ -93,10 +92,6 @@ class CameraPicker extends StatefulWidget {
9392
/// 返回页面时是否删除预览文件
9493
final bool shouldDeletePreviewFile;
9594

96-
/// Whether the orientation should be set to portrait.
97-
/// 相机是否需要强制竖屏
98-
final bool shouldLockPortrait;
99-
10095
/// The maximum duration of the video recording process.
10196
/// 录制视频最长时长
10297
///
@@ -135,7 +130,6 @@ class CameraPicker extends StatefulWidget {
135130
bool enablePinchToZoom = true,
136131
bool enablePullToZoomInRecord = true,
137132
bool shouldDeletePreviewFile = false,
138-
bool shouldLockPortrait = true,
139133
Duration maximumRecordingDuration = const Duration(seconds: 15),
140134
ThemeData? theme,
141135
int cameraQuarterTurns = 0,
@@ -163,7 +157,6 @@ class CameraPicker extends StatefulWidget {
163157
enablePinchToZoom: enablePinchToZoom,
164158
enablePullToZoomInRecord: enablePullToZoomInRecord,
165159
shouldDeletePreviewFile: shouldDeletePreviewFile,
166-
shouldLockPortrait: shouldLockPortrait,
167160
maximumRecordingDuration: maximumRecordingDuration,
168161
theme: theme,
169162
cameraQuarterTurns: cameraQuarterTurns,
@@ -374,12 +367,6 @@ class CameraPickerState extends State<CameraPicker>
374367
@override
375368
void initState() {
376369
super.initState();
377-
if (widget.shouldLockPortrait) {
378-
SystemChrome.setPreferredOrientations(<DeviceOrientation>[
379-
DeviceOrientation.portraitUp,
380-
DeviceOrientation.portraitDown,
381-
]);
382-
}
383370
WidgetsBinding.instance?.removeObserver(this);
384371

385372
// TODO(Alex): Currently hide status bar will cause the viewport shaking on Android.
@@ -398,9 +385,6 @@ class CameraPickerState extends State<CameraPicker>
398385

399386
@override
400387
void dispose() {
401-
if (widget.shouldLockPortrait) {
402-
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
403-
}
404388
if (!Platform.isAndroid) {
405389
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
406390
}
@@ -431,35 +415,6 @@ class CameraPickerState extends State<CameraPicker>
431415
}
432416
}
433417

434-
/// Turn camera preview according to the camera's orientation.
435-
/// 根据相机的旋转调整预览的旋转角度
436-
///
437-
/// Note: turns only takes effect when the orientation is locked.
438-
/// 注意:仅在设备自动旋转锁定的情况下生效。
439-
int _previewQuarterTurns(
440-
DeviceOrientation orientation,
441-
BoxConstraints constraints,
442-
) {
443-
int turns = -widget.cameraQuarterTurns;
444-
if (!widget.shouldLockPortrait) {
445-
return turns;
446-
}
447-
switch (orientation) {
448-
case DeviceOrientation.landscapeLeft:
449-
turns += -1;
450-
break;
451-
case DeviceOrientation.landscapeRight:
452-
turns += 1;
453-
break;
454-
case DeviceOrientation.portraitDown:
455-
turns += 2;
456-
break;
457-
default:
458-
break;
459-
}
460-
return turns;
461-
}
462-
463418
/// Adjust the proper scale type according to the [controller].
464419
/// 通过 [controller] 的预览大小,判断相机预览适用的缩放类型。
465420
_PreviewScaleType _effectiveScaleType(BoxConstraints constraints) {
@@ -1275,20 +1230,17 @@ class CameraPickerState extends State<CameraPicker>
12751230
}
12761231
final double _offsetHorizontal = (_width - constraints.maxWidth).abs() / -2;
12771232
final double _offsetVertical = (_height - constraints.maxHeight).abs() / -2;
1278-
if (widget.shouldLockPortrait) {
1279-
_preview = RotatedBox(
1280-
quarterTurns: _previewQuarterTurns(orientation, constraints),
1281-
child: _preview,
1282-
);
1283-
}
12841233
_preview = Stack(
12851234
children: <Widget>[
12861235
Positioned(
12871236
left: _offsetHorizontal,
12881237
right: _offsetHorizontal,
12891238
top: _offsetVertical,
12901239
bottom: _offsetVertical,
1291-
child: _preview,
1240+
child: RotatedBox(
1241+
quarterTurns: -widget.cameraQuarterTurns,
1242+
child: _preview,
1243+
),
12921244
),
12931245
],
12941246
);

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313

14-
camera: ^0.8.1+7
15-
device_info: ^2.0.2
14+
camera: ^0.9.2+1
1615
path: ^1.8.0
1716
path_provider: ^2.0.2
1817
photo_manager: ^1.3.0

0 commit comments

Comments
 (0)