你好,我在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>
)
])
)
}
}