cameraOverlay function

Widget cameraOverlay({
  1. required double padding,
  2. required double aspectRatio,
  3. required double radius,
  4. required Color color,
})

Implementation

Widget cameraOverlay(
    {required double padding,
    required double aspectRatio,
    required double radius,
    required Color color}) {
  return LayoutBuilder(builder: (context, constraints) {
    double parentAspectRatio = constraints.maxWidth / constraints.maxHeight;
    double horizontalPadding;
    double verticalPadding;

    if (parentAspectRatio < aspectRatio) {
      horizontalPadding = padding;
      verticalPadding = (constraints.maxHeight -
              ((constraints.maxWidth - 2 * padding) / aspectRatio)) /
          2;
    } else {
      verticalPadding = padding;
      horizontalPadding = (constraints.maxWidth -
              ((constraints.maxHeight - 2 * padding) * aspectRatio)) /
          2;
    }
    return Stack(fit: StackFit.expand, children: [
      Align(
          alignment: Alignment.centerLeft,
          child: Container(
            width: horizontalPadding,
            decoration: BoxDecoration(
              color: color,
            ),
          )),
      Align(
          alignment: Alignment.centerRight,
          child: Container(
            width: horizontalPadding,
            decoration: BoxDecoration(
              color: color,
            ),
          )),
      Align(
          alignment: Alignment.topCenter,
          child: Container(
            margin: EdgeInsets.only(
                left: horizontalPadding, right: horizontalPadding),
            height: verticalPadding,
            decoration: BoxDecoration(
              color: color,
            ),
          )),
      Align(
          alignment: Alignment.bottomCenter,
          child: Container(
            margin: EdgeInsets.only(
                left: horizontalPadding, right: horizontalPadding),
            height: verticalPadding,
            decoration: BoxDecoration(
              color: color,
            ),
          )),
      ColorFiltered(
          colorFilter: ColorFilter.mode(color, BlendMode.srcOut),
          child: Container(
            margin: EdgeInsets.symmetric(
                horizontal: horizontalPadding, vertical: verticalPadding),
            decoration: BoxDecoration(
                color: Colors.green,
                borderRadius: BorderRadius.circular(radius),
                border: Border.all(width: 20, color: Colors.greenAccent)),
          ))
    ]);
  });
}