@@ -37,7 +37,6 @@ class CameraPicker extends StatefulWidget {
37
37
this .enablePinchToZoom = true ,
38
38
this .enablePullToZoomInRecord = true ,
39
39
this .shouldDeletePreviewFile = false ,
40
- this .shouldLockPortrait = true ,
41
40
this .maximumRecordingDuration = const Duration (seconds: 15 ),
42
41
this .theme,
43
42
this .resolutionPreset = ResolutionPreset .max,
@@ -93,10 +92,6 @@ class CameraPicker extends StatefulWidget {
93
92
/// 返回页面时是否删除预览文件
94
93
final bool shouldDeletePreviewFile;
95
94
96
- /// Whether the orientation should be set to portrait.
97
- /// 相机是否需要强制竖屏
98
- final bool shouldLockPortrait;
99
-
100
95
/// The maximum duration of the video recording process.
101
96
/// 录制视频最长时长
102
97
///
@@ -135,7 +130,6 @@ class CameraPicker extends StatefulWidget {
135
130
bool enablePinchToZoom = true ,
136
131
bool enablePullToZoomInRecord = true ,
137
132
bool shouldDeletePreviewFile = false ,
138
- bool shouldLockPortrait = true ,
139
133
Duration maximumRecordingDuration = const Duration (seconds: 15 ),
140
134
ThemeData ? theme,
141
135
int cameraQuarterTurns = 0 ,
@@ -163,7 +157,6 @@ class CameraPicker extends StatefulWidget {
163
157
enablePinchToZoom: enablePinchToZoom,
164
158
enablePullToZoomInRecord: enablePullToZoomInRecord,
165
159
shouldDeletePreviewFile: shouldDeletePreviewFile,
166
- shouldLockPortrait: shouldLockPortrait,
167
160
maximumRecordingDuration: maximumRecordingDuration,
168
161
theme: theme,
169
162
cameraQuarterTurns: cameraQuarterTurns,
@@ -374,12 +367,6 @@ class CameraPickerState extends State<CameraPicker>
374
367
@override
375
368
void initState () {
376
369
super .initState ();
377
- if (widget.shouldLockPortrait) {
378
- SystemChrome .setPreferredOrientations (< DeviceOrientation > [
379
- DeviceOrientation .portraitUp,
380
- DeviceOrientation .portraitDown,
381
- ]);
382
- }
383
370
WidgetsBinding .instance? .removeObserver (this );
384
371
385
372
// TODO(Alex): Currently hide status bar will cause the viewport shaking on Android.
@@ -398,9 +385,6 @@ class CameraPickerState extends State<CameraPicker>
398
385
399
386
@override
400
387
void dispose () {
401
- if (widget.shouldLockPortrait) {
402
- SystemChrome .setPreferredOrientations (DeviceOrientation .values);
403
- }
404
388
if (! Platform .isAndroid) {
405
389
SystemChrome .setEnabledSystemUIOverlays (SystemUiOverlay .values);
406
390
}
@@ -431,35 +415,6 @@ class CameraPickerState extends State<CameraPicker>
431
415
}
432
416
}
433
417
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
-
463
418
/// Adjust the proper scale type according to the [controller] .
464
419
/// 通过 [controller] 的预览大小,判断相机预览适用的缩放类型。
465
420
_PreviewScaleType _effectiveScaleType (BoxConstraints constraints) {
@@ -1275,20 +1230,17 @@ class CameraPickerState extends State<CameraPicker>
1275
1230
}
1276
1231
final double _offsetHorizontal = (_width - constraints.maxWidth).abs () / - 2 ;
1277
1232
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
- }
1284
1233
_preview = Stack (
1285
1234
children: < Widget > [
1286
1235
Positioned (
1287
1236
left: _offsetHorizontal,
1288
1237
right: _offsetHorizontal,
1289
1238
top: _offsetVertical,
1290
1239
bottom: _offsetVertical,
1291
- child: _preview,
1240
+ child: RotatedBox (
1241
+ quarterTurns: - widget.cameraQuarterTurns,
1242
+ child: _preview,
1243
+ ),
1292
1244
),
1293
1245
],
1294
1246
);
0 commit comments