TND使用Flutter Platform View记录
Flutter Platform View 的文章,几乎都是猫大的
- 2020-08-08.Flutter 1.20 下的 Hybrid Composition 深度解析
- 2022-03-05.Fluttter 混合开发下 HybridComposition 和 VirtualDisplay 的实现与未来演进
- 2022-05-16.Flutter 3.0 之 PlatformView :告别 VirtualDisplay ,拥抱 TextureLayer
- 2025-04-24.Flutter 在全新 Platform 和 UI 线程合并后,出现了什么大坑和变化
- 2025-02-17.Flutter 正在推进全新 PlatformView 实现 HCPP, 它又用到了 Android 上的什么黑科技
而关于 VirtualDisplay,基本已经被废弃了,主要表现在性能和输入法等各种事件上
因为普通 App 的权限创建 VirtualDisplay 是不能带 OWN_FOCUS 的,所以内部 View 没有焦点
触摸输入,无障碍等都有不少问题, 也是将原本的 View 转换为了一整块 Surface
触摸事件需要判断是否落在了这块 Surface 上,才将事件处理后分发到对应的 View 上,期间需要转换坐标的
而输入法和无障碍的实现更复杂一些
所以这种方案 TND 也就不考虑了
官方文档
Hybrid Composition
Platform Views are rendered as they are normally. Flutter content is rendered into a texture. SurfaceFlinger composes the Flutter content and the platform views.
- best performance and fidelity of Android views.
- Flutter performance suffers.
- FPS of application will be lower.
- Certain transformations that can be applied to Flutter widgets will not work when applied to platform views.
Texture Layer (or Texture Layer Hybrid Composition)
Platform Views are rendered into a texture. Flutter draws the platform views (via the texture). Flutter content is rendered directly into a Surface.
- good performance for Android Views
- best performance for Flutter rendering.
- all transformations work correctly.
- quick scrolling (e.g. a web view) will be janky
- SurfaceViews are problematic in this mode and will be moved into a virtual display (breaking a11y)
- Text magnifier will break unless Flutter is rendered into a TextureView.
To create a platform view on Android, use the following steps:
Texture Layer Hybrid Composition
目前 TND 的任务窗口就是采用的这种方式,可以保证 Flutter 本身最好的性能
可以在 TND 开多个窗口,然后快速的移动窗口的位置观察
但是有缺点,Flutter 正在推进全新 PlatformView 实现 HCPP, 它又用到了 Android 上的什么黑科技 和官方的注释提到
1 | // These view types allow out-of-band drawing commands that don't notify the Android view |
大概就是如果是自渲染的 TextureView,是异步绘制的情况,需要主动调用 View#invalidate() ,不然视图不会更新
这个问题也非常影响 TND 的窗口设计,例如从后台回到前台的时候,需要主动调用 View#invalidate() ,否则窗口内容是空白的
并且,对于 TextureView 与一个 VirtualDisplay 绑定的情况下,视图的更新非常诡异,如果 VD 内的画面刷新,会触发 TextureView 的更新
但是如果是正在和 TextureView 交互,手指离开后的几帧,不会触发刷新
特别是在 Release 模式下,下面的情况在 Debug 下也出现
复现步骤
- 随便开一个 Android Task
- 使用 AAS 将 com.nightmare.neo.SecondaryActivity 启动到对应的显示器内
- 拖拽桌面的图标,到一个中间的位置,图标按理会回到计算后的位置,用
Scrcpy镜像对应的显示器也能看到图标回到了计算的位置 - 但是在 Neo 显示器内,图标卡在了手指离开的位置
Hybrid Composition
使用 initExpensiveAndroidView 强制 Hybrid Composition 模式
TND使用Flutter Platform View记录
https://bkkj.run/blog/2025/10/16/TND使用Flutter-Platform-View记录/

