简体   繁体   English

CustomPaint Over Camera Preview

[英]CustomPaint Over Camera Preview

I'm trying to use show a CustomPaint element over a camera preview in Flutter. 我正试图在Flutter的相机预览中使用show一个CustomPaint元素。 Right now, the CustomPaint element is being shown under the camera preview. 现在,CustomPaint元素显示在相机预览下。 I'm using the Flutter camera plugin to show the camera preview. 我正在使用Flutter相机插件来显示相机预览。 My code is below. 我的代码如下。

class _CameraPreviewState extends State<CameraPreview> {

  [...]

  Widget build(BuildContext context) {
  double height = MediaQuery.of(context).size.height;

  return new YidKitTheme(
    new Center(
      child: _isReady
        ? new Container(
          height: height / 2,
          child: new CustomPaint(
            painter: new GuidelinePainter(),
            child: new AspectRatio(
              aspectRatio: controller.value.aspectRatio,
              child: new CameraPreview(controller)
            ),
          )
        )
        : new CircularProgressIndicator()
      )
    );
  }
}

class GuidelinePainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = new Paint()
      ..strokeWidth = 3.0
      ..color = Colors.red
      ..style = PaintingStyle.stroke;

    var path = new Path()..lineTo(50.0, 50.0);
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
}

Change 更改

      child: new CustomPaint(
        painter: new GuidelinePainter(),
        child: new AspectRatio(

to

      child: new CustomPaint(
        foregroundPainter: new GuidelinePainter(),
        child: new AspectRatio(

painter draws first (ie the background), then the child is drawn, then foregroundPainter draws last on top of the child painter首先绘制(即背景),然后画出child ,然后foregroundPainter画画最后画在孩子的上方

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM