Skip to content

Commit a2245c0

Browse files
committed
🚀 Update exposure point widget with control.
1 parent d8bea1f commit a2245c0

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,23 +481,31 @@ class CameraPickerState extends State<CameraPicker>
481481
/// Use the [details] point to set exposure and focus.
482482
/// 通过点击点的 [details] 设置曝光和对焦。
483483
void setExposurePoint(TapDownDetails details) {
484+
// Ignore point update when the new point is less than 8% and higher than
485+
// 92% of the screen's height.
486+
if (details.globalPosition.dy < Screens.height / 12 ||
487+
details.globalPosition.dy > Screens.height / 12 * 11) {
488+
return;
489+
}
490+
realDebugPrint(
491+
'Setting new exposure point ('
492+
'x: ${details.globalPosition.dx}, '
493+
'y: ${details.globalPosition.dy}'
494+
')',
495+
);
484496
_lastExposurePoint.value = Offset(
485-
details.localPosition.dx,
486-
details.localPosition.dy,
497+
details.globalPosition.dx,
498+
details.globalPosition.dy,
487499
);
488500
_exposurePointDisplayTimer?.cancel();
489501
_exposurePointDisplayTimer = Timer(const Duration(seconds: 5), () {
490502
_lastExposurePoint.value = null;
491503
});
492-
controller.setExposurePoint(
493-
_lastExposurePoint.value.scale(1 / Screens.width, 1 / Screens.height),
494-
);
495-
realDebugPrint(
496-
'Setting new exposure point ('
497-
'x: ${_lastExposurePoint.value.dx}, '
498-
'y: ${_lastExposurePoint.value.dy}'
499-
')',
500-
);
504+
controller
505+
..setExposureMode(ExposureMode.auto)
506+
..setExposurePoint(
507+
_lastExposurePoint.value.scale(1 / Screens.width, 1 / Screens.height),
508+
);
501509
}
502510

503511
/// The method to take a picture.
@@ -770,7 +778,10 @@ class CameraPickerState extends State<CameraPicker>
770778
/// 用户手动设置的曝光点的区域显示
771779
Widget get _focusingAreaWidget {
772780
Widget _buildFromPoint(Offset point) {
773-
final double _width = Screens.width / 5;
781+
final double _pointWidth = Screens.width / 5;
782+
const double _exposureControlWidth = 20;
783+
final double _width = _pointWidth + _exposureControlWidth + 2;
784+
final bool _shouldReverseLayout = point.dx > Screens.width / 4 * 3;
774785

775786
final double _effectiveLeft = math.min(
776787
Screens.width - _width,
@@ -785,8 +796,25 @@ class CameraPickerState extends State<CameraPicker>
785796
left: _effectiveLeft,
786797
top: _effectiveTop,
787798
width: _width,
788-
height: _width,
789-
child: ExposurePointWidget(key: ValueKey<int>(currentTimeStamp)),
799+
height: _pointWidth,
800+
child: Row(
801+
textDirection:
802+
_shouldReverseLayout ? TextDirection.rtl : TextDirection.ltr,
803+
children: <Widget>[
804+
ExposurePointWidget(
805+
key: ValueKey<int>(currentTimeStamp),
806+
size: _pointWidth,
807+
),
808+
const SizedBox(width: 2),
809+
SizedBox.fromSize(
810+
size: Size(_exposureControlWidth, _pointWidth),
811+
child: const Icon(
812+
Icons.wb_sunny_outlined,
813+
size: _exposureControlWidth,
814+
),
815+
),
816+
],
817+
),
790818
);
791819
}
792820

@@ -916,7 +944,8 @@ class CameraPickerState extends State<CameraPicker>
916944
),
917945
);
918946
}
919-
return const SizedBox.expand();},
947+
return const SizedBox.expand();
948+
},
920949
),
921950
_exposureDetectorWidget(context),
922951
SafeArea(

lib/src/widget/exposure_point_widget.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import 'builder/tween_animation_builder_2.dart';
1111
class ExposurePointWidget extends StatelessWidget {
1212
const ExposurePointWidget({
1313
Key key,
14-
this.size = 90,
15-
}) : super(key: key);
14+
@required this.size,
15+
}) : assert(size != null),
16+
super(key: key);
1617

1718
final double size;
1819

0 commit comments

Comments
 (0)