如何创建 iOS 或 Android 视图作为组件?

问题描述 投票:0回答:1

我可以创建 iOS 或 Android 视图作为组件吗?我想在 Flame 中使用 Native VideoPlayer。

如:NativeView -> Flutter Widget -> Flame 组件 或 NativeView -> Flame 组件

我已成功尝试将 NativeView 桥接到 Flutter Widget,但我不知道如何将其桥接为 Flame 组件。

flame
1个回答
0
投票

我认为没有直接的方法可以做到这一点,但您可以使用 Flutter Widget 作为中介。比如:

  1. 创建您的 NativeView。
  2. 将 NativeView 桥接到 Flutter Widget(您提到过您已经完成了此操作)
  3. 使用 WidgetComponent 类创建一个 Flame Widget 组件,该类允许您使用 Flutter Widget 作为 Flame 中的组件。

import 'package:flame/components.dart';

class WidgetComponent extends WidgetComponent {
  WidgetComponent()
      : super(
          widget: FlutterWidget(), // Replace this with your Flutter Widget
          priority: 1,
        );
}

© www.soinside.com 2019 - 2024. All rights reserved.