首页 > 解决方案 > 从外部更新 RepaintBoundary 内部

问题描述

如何从外部更新 RepaintBoundary,是否可能?我正在开发某种绘图应用程序,如果用户点击按钮,我会得到容器的屏幕截图,如果用户点击删除按钮,绘画正在清除,但在我的情况下,点列表正在清除,但容器(绘图本身)不清除。

    SingleChildScrollView(//physics: NeverScrollableScrollPhysics(),
          child: Column(
            children: <Widget>[
              RepaintBoundary(
                key: _signKey,
                child: new Container(
                  child: GestureDetector(
                    onPanUpdate: (DragUpdateDetails details) {
                      setState(() {
                        RenderBox object = context.findRenderObject();
                        Offset _localPosition =
                        object.globalToLocal(details.globalPosition);
                        points = new List.from(points)
                          ..add(_localPosition);
                      });
                    },
                    onPanEnd: (DragEndDetails details) => points.add(null),
                    child: new CustomPaint(
                      painter: new DrawPainter(points: points),
                      size: Size.infinite,
                    ),
                  ),

                ),
              ),
              Row(
                children: <Widget>[
                  FlatButton(
                    padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8)),
                    color: Colors.redAccent,
                    textColor: Colors.black,
                    onPressed: (){
                      setState(() {
                        points.clear();
                      });
                    },
                    child: Text('Sil'),
                  ),
                ],
              ),
            ],
          ),
        );

标签: flutterdartcontainerscross-platform

解决方案


推荐阅读