Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 将CustomPainter与isComplex一起使用,将改变颤振_Flutter - Fatal编程技术网

Flutter 将CustomPainter与isComplex一起使用,将改变颤振

Flutter 将CustomPainter与isComplex一起使用,将改变颤振,flutter,Flutter,我使用具有两个属性的CustomPainter:isComplex和willChange 使用它们和不使用它们没有区别 请告诉我他们之间的区别 void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp&

我使用具有两个属性的CustomPainter:isComplex和willChange

使用它们和不使用它们没有区别

请告诉我他们之间的区别

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      isComplex: true,
      willChange: false,
      painter: MyPainter(),
    );
  }
}

class MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    for (int i = 0; i < size.width; ) {
      Color color = Colors.green;
      if ((i/10)%2==0){
        color = Colors.red;
      }
      Rect rect = Rect.fromLTWH(
          i + 10.0, size.height / 3, size.width / 10, size.height / 3);
      canvas.drawRect(rect, Paint()..color = color);
      i +=10;
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}
void main()=>runApp(MyApp());
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
@凌驾
小部件构建(构建上下文){
返回自定义油漆(
是的,
willChange:错,
画家:我的画家(),
);
}
}
类MyPainter扩展了CustomPainter{
@凌驾
空心油漆(帆布,尺寸){
对于(int i=0;i
接下来,我尝试更改isComplex和willChange的值,没有区别


提前感谢

您可以查看属于
CustomPainter
子类的文档:

isComplexwillChange是对合成器光栅缓存的提示 并且不能为null

:

绘制是否足够复杂,可以从缓存中获益

合成器包含一个光栅缓存,用于保存中图层的位图 以避免在每个层上重复渲染这些层的成本 框架如果未设置此标志,则合成器将应用自己的 用于确定此层是否足够复杂以 从缓存中获益

:

是否应告知光栅缓存此绘制是可能的 在下一帧中更改


因此,基本上看不到任何视觉变化,但正确处理它们将提高缓存的使用,从而提高渲染成本

你到底想要实现什么?你的目标是什么?@pskink:我想看看它们的区别,以防我改变它们的价值。