flutter - Flutter Repaint 边界重绘规则
问题描述
每次方法中的变量_lastIndex
更改时,我都想重新绘制我的 RepaintBoundary 小部件的孩子setState()
。基本上,我希望 RepaintBoundary 的行为与适用于任何普通 Container 的行为相同 - 但出于不相关的原因,我需要 RepaintBoundary 而不是 Container。我玩了一下,发现在第一个示例中发生更改时,子 ( MyPainter
) 会重新渲染_lastIndex
,而在第二个示例中则不会。它背后的规则是什么让这两个例子的行为如此不同?
1.例子
RepaintBoundary(
key: globalKey,
child: Container(
child: Container(
child: new CustomPaint(
child: Text(_lastIndex.toString()), // MyPainter is re-rendered because of this line
painter: new MyPainter(index: _lastIndex), // while this line doesn't have any effect on re-rendering
isComplex: true,
willChange: false,
),
)
)
),
2.例子
RepaintBoundary(
key: globalKey,
child: Container(
child: Container(
child: new CustomPaint(
painter: new MyPainter(index: _lastIndex),
isComplex: true,
willChange: false,
),
)
)
),
解决方案
推荐阅读
- c++ - boost变体可以为非活动变体调用析构函数吗?
- python - Python:UnicodeDecodeError:'utf-8'编解码器无法解码位置 37 的字节 0x96:无效的起始字节
- java - 消费 Post 方法 Rest + SpringBoot
- android - 为什么我的 webview 应用程序正在下载 .bin 文件?
- ember.js - Ember 保存数据以存储和显示,无需服务器 api
- html - Mojave Html Mail 暗模式:防止某些元素被更改
- android - 当我的应用程序关闭时,如何以编程方式防止设备关闭显示器(屏幕超时)?
- android - 向下滑动刷新有问题
- java - 为什么在此子字符串方法中出现 StringIndexOutOfBoundsException 错误?
- reactjs - Laravel 受保护的 API 路由响应返回 HTML 而不是 JSON