问题描述
我正在将Redux与Flutter一起用于状态管理.每当我调度动作时,我都想知道重新渲染了哪些小部件.有什么办法吗?
I am using Redux with Flutter for state management. Whenever I dispatch an action, I want to know which widgets were re-rendered. Is there any way of doing it?
推荐答案
每当一个小部件更新时,情况就扑朔迷离;整个小部件树重新绘制.所以...不.
In flutter, whenever one widget update ; the whole widget tree repaint. So... no.
但是您也可以通过在树中插入 RepaintBoundary
小部件来手动引入重绘边界".这明确地告诉flutter为其子级创建一个新的绘画层(这意味着内存缓存).这样,每当该子项更新时,它也不会重绘其父项.
But you can also introduce "repaint boundaries" manually by inserting in your tree a RepaintBoundary
widget. This explicitly tells flutter to create a new painting layer for it's child (which implies memory cache). So that whenever that child updates, it won't repaint it's parent too.
您可以做的是在重新绘制重新绘制边界时进行调试.
What you can do is instead debug when a repaintboundary is repainted.
为此,您可以通过以下方式启用彩虹重绘:
For this you can enable repaint rainbow by :
- 在使用
flutter run
时按 - 使用带有
ctrl/cmd + shift + p
的vscodeDart Code
扩展名和enable repaint rainbow
t
- pressing
t
when usingflutter run
- using vscode
Dart Code
extension with actrl/cmd + shift + p
andenable repaint rainbow
这篇关于Flutter:如何调试状态更改后重新呈现的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!