当前位置:网站首页>Flutter 打印Widget 层级列表
Flutter 打印Widget 层级列表
2022-07-20 06:58:00 【bawomingtian123】
在Flutter实际开发过程中,偶尔调试Widget生命周期时,需要打印Widget的路径,从路径中查找组件inState生命周期触发的原因。
实际案例:
在用Container 包裹一个组件,发现该组件instate生命周期莫名被调用,根据打印出来的路径,定位到Container的Decoration影响。
DrilgrassWheelList ← Container ← DecoratedBox ← Container ← _RawMouseRegion ← MouseRegion ← Listener ← Listener ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← Positioned-[GlobalObjectKey WheelListItem#705e9] ←
在上述案例中,我们通过打印Widget路径,很清晰地知道组件的层级关系。
关键代码如下
DebugCreator(context as Element).toString()
/// A wrapper class for the [Element] that is the creator of a [RenderObject].
///
/// Setting a [DebugCreator] as [RenderObject.debugCreator] will lead to better
/// error messages.
class DebugCreator {
/// Create a [DebugCreator] instance with input [Element].
DebugCreator(this.element);
/// The creator of the [RenderObject].
final Element element;
@override
String toString() => element.debugGetCreatorChain(12);
}
默认这个方法会返回12层的结构。
边栏推荐
- 【递归 & 分治】压缩变换(使用区间树和二分法,递归统计指定区间内数字种类)
- Thirteen grammar learning of reflect
- Two dimensional convolution Chinese microblog emotion classification project
- OTA online upgrade practice record (still need to be updated)
- 《PolarDB for Postgres SQL 》主要讲了什么?
- 国内的边缘计算组织和产品调研
- Swift reads the bundle file
- Dat in threejs Use of GUI to display folder click time and color palette
- Deep residual learning for image recognition -- RESNET classic paper
- 【翻译】读博士一年后对机器学习工程的思考
猜你喜欢
keras MNIST手寫數字數據集數字識別
Top ten best automated test tools in the world in 2022
Deep residual learning for image recognition -- RESNET classic paper
Jmeter关联
Leetcode skimming -- drip record 016
XMind中拷贝和复制的区别
extern 、static 作为全局变量的使用与差异
03 BeautifulSoup解析库
selenium框架操作stealth.min.js文件隐藏浏览器指纹特征
Docker learning notes (12) -- practical deployment of redis cluster
随机推荐
LeetCode刷题--点滴记录016
Summary of shangyitong project
mpf4_ Pricing European American barrier options_ CRR_ Leisen-Reimer_ Greeks_ Binary tree trigeminal tree grid_ Fine differences (explicit implicit) crank Nicolson_ Imp volatility
keras MNIST手寫數字數據集數字識別
[learning notes] insert addition
Redis lock oversold to solve the problem
C language structure flexible array
# CF #807 Div.2(A - D)
One dimensional convolution English film review emotion classification project
QT笔记——自定义的流式布局QFlowLayout
动态规划--数位dp
HCIP-7. LSA header of OSPF
2022年暑假ACM热身练习3
[QNX hypervisor 2.2 user manual] directory
Renren code generator -- simplify your development
网络安全专业术语英文缩写对照表
9 suggestions for quickly improving programming ability
The projection layer released by leaflet loading hypergraph reports an error uncaught no projection definition for code XXXX
What are the six access database objects? What is the most important difference between access and excel?
[translation] thinking about machine learning engineering after a year of doctoral study