Flutter 每日翻译之 Widget

Describes the configuration for an **Element**.

描述元素的配置

Widgets are the central class hierarchyin the Flutter framework.

组件是 Flutter Framework 层次结构中的中心类

A widget is an immutable description of part of a user interface

控件是用户界面****不可变描述的一部分

Widgets can be inflated into elements, which manage the underlying****render tree.

控件能被解析到元素列表中,被底层****呈现树管理

Widgets themselves have no mutable state (all their fields must be final).

If you wish to associate mutable state with a widget, considerusing a

StatefulWidget, which creates a State object (via

StatefulWidget.createState) whenever it is inflated into an element and
incorporatedinto the tree.

控件自身拥有不可变状态(他们的属性必须是final),如果你希望关联到一个可变状态的控件,请考虑使用StatefulWidget,创建一个State 类(通过StatefulWidget.createState),不管如何,他会被解析成元素合并到树中

A given widgetcan be included in the tree zero or more times.In particular a given widget can be placed in the tree multiple times. Each time a widget is placed in the tree, it is inflated into an Element, which means a widget that is incorporated into the tree multiple times will be inflated

multiple times.

给定的小部件可以在树中包含零次或多次。特别是给定的小部件可以多次放置在树中。每次一个小部件被放置在树中,它被解析成一个Element,这意味着一个多次合并到树中的小部件将被充气

很多次了。

The key property controls how one widget replaces another widget in the tree. If the runtimeType and key properties of the two widgets are operator==, respectively, then the new widget replaces the old widget by updating the underlying element (i.e., by calling Element.update with the new widget). Otherwise, the old element is removed from the tree, the new widget is inflated into an element, and the new element is inserted into the tree.

key属性控制一个小部件如何替换树中的另一个小部件。如果两个小部件的runtimeType和key属性分别为operator==,则新小部件依次通过更新底层元素(即通过调用element)来替换旧小部件。用新的小部件更新)。否则,将从树中删除旧元素,将新小部件解析为元素,并将新元素插入到树中。

StatefulWidget and State, for widgets that can build differentlyseveral timesover their lifetime.

StatefulWidget和State,用于在其生命周期中可以多次构建不同的小部件。

InheritedWidget, for widgets that introduce ambientstate that can be read by descendantwidgets.

这个控件引入环境 状态它能够被子控件读取

StatelessWidget, for widgets that always build the same way given a particularconfiguration and ambientstate.

StatelessWidget,用于在给定特定配置和环境状态时始终以相同方式构建的小部件。

相关推荐
小 黄 鸡4 小时前
Flutter 面试必会知识点详解(从基础到进阶)
flutter·面试·职场和发展
大龄秃头程序员12 小时前
Flutter 最少代码验证:为什么子 Isolate 调原生,一定要先回到主 Isolate?
flutter
FungLeo12 小时前
成为全栈·Flutter App 篇·分类、标签与搜索:移动端内容发现
flutter·移动开发·标签·搜索·分类管理·成为全栈
m0_7381858214 小时前
Flutter 鸿蒙化实战:the_apple_sign_in 适配 OpenHarmony,Apple 登录
flutter·华为·harmonyos·鸿蒙
m0_7381858214 小时前
Flutter 鸿蒙化实战:umeng_analytics_plugin 适配 OpenHarmony,友盟统计
flutter·华为·harmonyos·鸿蒙
FungLeo15 小时前
成为全栈·Flutter App 篇·列表分页与下拉刷新:去重、失败保留和返回位置
flutter·移动开发·下拉刷新·分页加载·列表优化·成为全栈
大龄秃头程序员17 小时前
【从一道面试题入手】深入理解 Dart 事件循环调度机制
flutter
恋猫de小郭18 小时前
Kotlin 2.5 的 Companion 改造,对 KMP 的重要升级
android·前端·flutter
程序员老刘1 天前
Flutter你看看人家RN
flutter·react native·ai编程
大龄秃头程序员2 天前
【Flutter Bloc 从 0 到 1】用最少代码跑通 Bloc
flutter