buildFocusingPoint method

Widget buildFocusingPoint({
  1. required CameraValue cameraValue,
  2. required BoxConstraints constraints,
})

The area widget for the last exposure point that user manually set. 用户手动设置的曝光点的区域显示

Implementation

Widget buildFocusingPoint({
  required CameraValue cameraValue,
  required BoxConstraints constraints,
}) {
  Widget buildControls(double size, double height) {
    const double verticalGap = 3;
    final ExposureMode exposureMode = cameraValue.exposureMode;
    final bool isLocked = exposureMode == ExposureMode.locked;
    return Column(
      children: <Widget>[
        ValueListenableBuilder<bool>(
          valueListenable: isFocusPointDisplays,
          builder: (_, bool value, Widget? child) => AnimatedOpacity(
            duration: _kDuration,
            opacity: value ? 1 : 0,
            child: child,
          ),
          child: GestureDetector(
            onTap: switchExposureMode,
            child: SizedBox.fromSize(
              size: Size.square(size),
              child: Icon(
                isLocked ? Icons.lock_rounded : Icons.lock_open_rounded,
                size: size,
                color: isLocked ? _lockedColor : null,
              ),
            ),
          ),
        ),
        const SizedBox(height: verticalGap),
        Expanded(
          child: buildExposureSlider(
            mode: exposureMode,
            size: size,
            height: height,
            gap: verticalGap,
          ),
        ),
        const SizedBox(height: verticalGap),
        SizedBox.fromSize(size: Size.square(size)),
      ],
    );
  }

  Widget buildFromPoint(Offset point) {
    const double controllerWidth = 20;
    final double pointWidth = constraints.maxWidth / 5;
    final double exposureControlWidth =
        pickerConfig.enableExposureControlOnPoint ? controllerWidth : 0;
    final double width = pointWidth + exposureControlWidth + 2;
    final bool shouldReverseLayout = point.dx > constraints.maxWidth / 4 * 3;
    final double effectiveLeft = math.min(
      constraints.maxWidth - width,
      math.max(0, point.dx - width / 2),
    );
    final double effectiveTop = math.min(
      constraints.maxHeight - pointWidth * 3,
      math.max(0, point.dy - pointWidth * 3 / 2),
    );
    return Positioned(
      left: effectiveLeft,
      top: effectiveTop,
      width: width,
      height: pointWidth * 3,
      child: ExcludeSemantics(
        child: Row(
          textDirection:
              shouldReverseLayout ? TextDirection.rtl : TextDirection.ltr,
          children: <Widget>[
            CameraFocusPoint(
              key: ValueKey<int>(DateTime.now().millisecondsSinceEpoch),
              size: pointWidth,
              color: theme.iconTheme.color!,
            ),
            if (pickerConfig.enableExposureControlOnPoint)
              const SizedBox(width: 2),
            if (pickerConfig.enableExposureControlOnPoint)
              SizedBox.fromSize(
                size: Size(exposureControlWidth, pointWidth * 3),
                child: buildControls(controllerWidth, pointWidth * 3),
              ),
          ],
        ),
      ),
    );
  }

  return ValueListenableBuilder<Offset?>(
    valueListenable: lastExposurePoint,
    builder: (_, Offset? point, __) {
      if (point == null) {
        return const SizedBox.shrink();
      }
      return buildFromPoint(point);
    },
  );
}