Flutter之Key简析

Posted 郭梧悠

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter之Key简析相关的知识,希望对你有一定的参考价值。

在博主《Flutter之GlobalKey详解》和《Flutter之Widget 更新机制原理浅析》中两篇博文中简单的说明了key的作用,这里在简单做个笔记(翻译子官方文档),加深自己对key的理解。

官方对于key的解释如下:

///Key对象是用作Widget、Element、SemanticsNode的标识符,也就是唯一ID
/// A [Key] is an identifier for [Widget]s, [Element]s and [SemanticsNode]s.

///当newWidget和Element.widget的key相等时候,就满足了Element更新的条件之一。之二是
//oldWidget.runtimeType == newWidget.runtimeType,如果都满足的话,就可以将newWidget赋值给Element的Widget变量。
/// A new widget will only be used to update an existing element if its key is
/// the same as the key of the current widget associated with th

以上是关于Flutter之Key简析的主要内容,如果未能解决你的问题,请参考以下文章

Flutter之SchedulerBinding简析

Flutter之GetX入门指南 ObxWidget原理剖析

Flutter之GetX入门指南 ObxWidget原理剖析

Flutter样式和布局控件简析

Flutter跨组件共享状态的利器Provider简析

Flutter跨组件共享状态的利器Provider框架简析