Flutter:如何调试状态更改后重新呈现的小部件 [英] Flutter : How to Debug which widgets re-rendered on state change

查看:67
本文介绍了Flutter:如何调试状态更改后重新呈现的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将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
  • 时按 t
  • 使用带有 ctrl/cmd + shift + p 的vscode Dart Code 扩展名和 enable repaint rainbow
  • pressing t when using flutter run
  • using vscode Dart Code extension with a ctrl/cmd + shift + p and enable repaint rainbow

这篇关于Flutter:如何调试状态更改后重新呈现的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆