buildCaptureActions method
Widget
buildCaptureActions({
- required BuildContext context,
- required BoxConstraints constraints,
- CameraController? controller,
Capture action's widget. 拍照操作区
This displayed at the top of the screen. 该区域显示在屏幕下方。
Implementation
Widget buildCaptureActions({
required BuildContext context,
required BoxConstraints constraints,
CameraController? controller,
}) {
const fallbackSize = 150.0;
final previewSize = controller?.value.previewSize;
final orientation = controller?.value.deviceOrientation ??
MediaQuery.orientationOf(context);
final isPortrait = orientation.toString().contains('portrait');
double effectiveSize;
if (controller == null || pickerConfig.enableScaledPreview) {
effectiveSize = lastCaptureActionsEffectiveHeight ?? fallbackSize;
} else if (previewSize != null) {
Size constraintSize = Size(constraints.maxWidth, constraints.maxHeight);
if (isPortrait && constraintSize.aspectRatio > 1 ||
!isPortrait && constraintSize.aspectRatio < 1) {
constraintSize = constraintSize.flipped;
}
if (isPortrait) {
effectiveSize = constraintSize.height -
constraintSize.width * previewSize.aspectRatio;
} else {
effectiveSize = constraintSize.width -
constraintSize.height * previewSize.aspectRatio;
}
} else if (lastCaptureActionsEffectiveHeight != null) {
effectiveSize = lastCaptureActionsEffectiveHeight!;
} else {
// Fallback to a reasonable height.
effectiveSize = fallbackSize;
}
if (effectiveSize <= 0) {
realDebugPrint(
'Unexpected layout size calculation: $effectiveSize, '
'portrait: $isPortrait, '
'orientation: $orientation',
);
effectiveSize = fallbackSize;
} else if (effectiveSize < fallbackSize) {
effectiveSize = fallbackSize;
}
lastCaptureActionsEffectiveHeight = effectiveSize;
return Container(
width: isPortrait ? null : effectiveSize,
height: isPortrait ? effectiveSize : null,
padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
child: Flex(
direction: isPortrait ? Axis.horizontal : Axis.vertical,
verticalDirection: orientation == DeviceOrientation.landscapeLeft
? VerticalDirection.up
: VerticalDirection.down,
children: <Widget>[
const Spacer(),
Expanded(
child: Center(
child: buildCaptureButton(context, constraints),
),
),
if (controller != null &&
!controller.value.isRecordingVideo &&
cameras.length > 1)
Expanded(
child: RotatedBox(
quarterTurns: !enableScaledPreview ? cameraQuarterTurns : 0,
child: buildCameraSwitch(context),
),
)
else
const Spacer(),
],
),
);
}