如何避免在变换时重绘CustomePainter

时间:2019-02-05 22:30:54

标签: dart flutter

你好,我在Transform类中使用CustomePainter。

如果我不想重绘CustomPainter怎么办? 我添加了shouldRepaint返回false,但是不起作用。

@override
  bool shouldRepaint(HexagonalCanvas oldDelegate) {
    return false;
  }

手势检测和转换后,从头开始创建CustomePainter。

class _YourWidgetState extends State<YourWidget> {

double finalScale = 1.0;
double finalRotation = 0.0;
ScaleUpdateDetails scaleStart;

Widget build() {
  return GestureDetector(
onScaleStart: (ScaleUpdateDetails details) => {
    //
    scaleStart = details;
},
onScaleUpdate: (ScaleUpdateDetails details) => {
   setState(() => {
     finalScale =  <calculate final scale here>
     finalRotation =  <calculate final rotation here>
   })
},
child: Stack(children: [
   <image widget>,
   Transform(
      transform: Matrix4.diagonal3(Vector3(finalScale, finalScale, finalScale))..rotateZ(finalRotation),
      child: <CustomePainter widget>
   )
])
          )
        }

 }

0 个答案:

没有答案