Flutter API文档 - RepaintBoundary

RepaintBoundary class

A widget that creates a separate display list for its child.
一个能够为 child 创建一个独立的display list 的widget。

This widget creates a separate display list for its child, which can improve performance if the subtree repaints at different times than the surrounding parts of the tree.
当使用RepaintBoundary widget为 child(子树) 创建独立的display list ,如果子树在与树的父容器等部分在不同的时间repaint,则可以提高性能。

This is useful since RenderObject.paint may be triggered even if its associated Widget instances did not change or rebuild. A RenderObject will repaint whenever any RenderObject that shares the same Layer is marked as being dirty and needing paint (see RenderObject.markNeedsPaint), such as when an ancestor scrolls or when an ancestor or descendant animates.
这很有用,因为 RenderObject.paint 很有可能会被触发,即使其关联的 Widget 实例没有更改或rebuild。 每当共享同Layer的任何 RenderObject 被标记为dirty且需要rebuild时,(该Layer下所有的)RenderObject 都会rebuild(请参阅 RenderObject.markNeedsPaint),例如当祖先widget滚动、祖先widget animate 、后代widget animate 等情况下。

Containing RenderObject.paint to parts of the render subtree that are actually visually changing using RepaintBoundary explicitly or implicitly is therefore critical to minimizing redundant work and improving the app’s performance.
因此,将 RenderObject.paint 包含到render子树的某些部分,这些部分实际上是使用 RepaintBoundary 显式或隐式地在视觉上发生变化,这对于最大限度地减少冗余工作和提高应用程序的性能至关重要。

When a RenderObject is flagged as needing to paint via RenderObject.markNeedsPaint, the nearest ancestor RenderObject with RenderObject.isRepaintBoundary, up to possibly the root of the application, is requested to repaint. That nearest ancestor’s RenderObject.paint method will cause all of its descendant RenderObjects to repaint in the same layer.
当通过 RenderObject.markNeedsPaint 将 RenderObject 标记为需要 paint时,将会向上遍历最近的具有 RenderObject.isRepaintBoundary 的祖先 RenderObject,直到可能是app的root,都被请求repaint。 最接近祖先的 RenderObject.paint 方法将导致其所有后代 RenderObject 在同Layer中repaint。

RepaintBoundary is therefore used, both while propagating the markNeedsPaint flag up the render tree and while traversing down the render tree via PaintingContext.paintChild, to strategically contain repaints to the render subtree that visually changed for performance. This is done because the RepaintBoundary widget creates a RenderObject that always has a Layer, decoupling ancestor render objects from the descendant render objects.
因此,在将 markNeedsPaint 标志向上传播render树以及通过 PaintingContext.paintChild 向下遍历render树时都使用了 RepaintBoundary,以策略性地包含对渲染子树的重绘,这些渲染子树在视觉上会因性能而发生变化。 这样做是因为 RepaintBoundary widget创建了一个始终自带Layer的 RenderObject,从而将祖先renderObject与后代renderObject解耦。

RepaintBoundary has the further side-effect of possibly hinting to the engine that it should further optimize animation performance if the render subtree behind the RepaintBoundary is sufficiently complex and is static while the surrounding tree changes frequently. In those cases, the engine may choose to pay a one time cost of rasterizing and caching the pixel values of the subtree for faster future GPU re-rendering speed.
如果 RepaintBoundary 包含的render子树足够复杂并且是静态的,而周围的渲染树经常变化,那么 RepaintBoundary 可能会向引擎暗示它应该进一步优化animation性能的进一步副作用。 在这些情况下,引擎可能会选择一次性支付raster和缓存子树的像素值的成本,以实现更快的即将到来的 GPU 重新渲染的速度。

Several framework widgets insert RepaintBoundary widgets to mark natural separation points in applications. For instance, contents in Material Design drawers typically don’t change while the drawer opens and closes, so repaints are automatically contained to regions inside or outside the drawer when using the Drawer widget during transitions.
几个framework widget插入 RepaintBoundary widget以标记app程序中的自然分隔点。 例如,Material Design drawer中的内容通常不会在drawer打开和关闭时更改,因此在转换期间使用 Drawer widget时,repaint会自动包含在抽屉内部或外部的区域中。

See also:
也可以看看:

debugRepaintRainbowEnabled, a debugging flag to help visually monitor render tree repaints in a running app.
debugRepaintRainbowEnabled,一个调试标志,用于帮助直观地监控正在运行的应用程序中的render树的repaint。

debugProfilePaintsEnabled, a debugging flag to show render tree repaints in the observatory’s timeline view.
debugProfilePaintsEnabled,一个调试标志,用于在observatory时间线视图中显示render树的repaint。

译者推荐:可以阅读《Flutterl实战》的Flutter 绘制原理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Flutter API文档Flutter软件开发框架的核心文档资料,可以帮助开发者更轻松地使用Flutter框架进行应用程序开发。此文档包括Flutter框架所有可用的类、方法、属性、常量以及其他相关数据类型,在Flutter框架开发中是必不可少的参考资料。 Flutter API文档详细记录了Flutter框架中的所有接口和函数,并提供了实际应用示例,能够帮助开发者理解和掌握Flutter框架的各种用法。API文档十分完整,在参考手册中能够找到各种细节方面的注意事项,能够帮助开发者更好地实现应用程序的开发需求。 Flutter API文档的优点在于提供了高质量的资料和示例,非常适合给Flutter初学者使用。此外,与其他API文档相比,Flutter API文档有一个社区版本,让开发者可以共同协作编辑和完善,提高了文档的质量和实用性。 总之,Flutter API文档Flutter软件开发者提供了必不可少的参考资料,能够帮助开发者更高效地使用Flutter框架开发应用程序。 ### 回答2: Flutter 是由 Google 推出的跨平台移动应用开发框架,其 API 文档包含了开发者所需的所有方法、类和属性,详尽地介绍了 Flutter 所提供的所有功能。 Flutter API 文档分为两部分:Flutter 核心库和 Flutter 框架库。在核心库中,开发者可以找到所有基本的构建块,例如文本和按钮,以及构建应用程序所需的工具和函数。在框架库中,开发者可以找到关于导航、路由、动画和交互式组件等高级主题的信息。 通过 Flutter API 文档,开发者可以轻松了解和应用 Flutter 的功能,包括布局、主题定制、状态管理、持久存储和网络请求等。文档采取树形结构,方便快速定位所需的类或方法,还提供了常用示例和代码演示,方便开发者理解和应用。 总之,Flutter API 文档是开发 Flutter 应用的必备工具,它展示了 Flutter 的一切,使得开发者可以轻松地构建出优秀的移动应用。 ### 回答3: Flutter是一款快速、高效、现代化的跨平台应用程序开发框架。 Flutter通过具备丰富的API文档帮助用户高质量的构建应用程序。 Flutter API文档提供了完整的应用程序开发的细节,可以使用这些文档来构建优秀的应用程序。文档中主要涵盖了Flutter中所有类,包括小部件、组件等等,同时还包括API函数定义、参数、返回值等详细信息。 在Flutter API文档中,你可以快速轻松地发现所需的小部件和功能,了解它们的作用以及如何使用它们。它还提供了示例代码,以帮助开发人员更好地理解如何使用API,构建正确的应用程序。 除了API文档外,Flutter还在其官网上提供了大量的学习资源,包括演示应用、插件、视频教程、代码示例和博客文章等,这些资源对开发人员的学习和实践都非常有帮助。 总之,Flutter API文档让应用程序开发者更加轻松地使用 Flutter 构建跨平台应用程序。它是一个强大而又易于使用的文档库,是Flutter生态系统中不可或缺的一部分。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值