Flutter 3 升级后,我的嵌入式原生 Android 视图速度很慢,对点击事件没有反应并崩溃

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

我的 flutter 应用程序中有一个包含自定义视频播放器的本机视图。 Flutter 3 升级后,视图开始卡顿,无法正确调整大小,甚至在调整大小时停止播放,并且对点击事件没有反应。

是否有人知道 flutter 是否改变了任何东西?我在变更日志中找不到任何内容。

android flutter video rendering
2个回答
0
投票

我在变更日志中没有找到任何内容,但发现了这个flutter问题:https://github.com/flutter/flutter/issues/103630

我在那里找到了这个解决方案:将

PlatformViewsService.initSurfaceAndroidView
替换为
PlatformViewsService.initExpensiveAndroidView
以获得旧的渲染行为。

它说如果可以避免的话就不应该这样做,但就我而言,这是完美的解决方案。

@override
  Widget buildView(
      Map<String, dynamic> creationParams,
      OnPlatformViewCreatedCallback onPlatformViewCreated,
      Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers) {
    if (defaultTargetPlatform == TargetPlatform.android) {
-      if (useHybridComposition) {
        return PlatformViewLink(
          viewType: 'plugins.flutter.io/mapbox_gl',
          surfaceFactory: (
            BuildContext context,
            PlatformViewController controller,
          ) {
            return AndroidViewSurface(
              controller: controller as AndroidViewController,
              gestureRecognizers: gestureRecognizers ??
                  const <Factory<OneSequenceGestureRecognizer>>{},
              hitTestBehavior: PlatformViewHitTestBehavior.opaque,
            );
          },
          onCreatePlatformView: (PlatformViewCreationParams params) {
-            final SurfaceAndroidViewController controller =
+            final AndroidViewController controller =
-                PlatformViewsService.initSurfaceAndroidView(
+                PlatformViewsService.initExpensiveAndroidView(
              id: params.id,
              viewType: 'plugins.flutter.io/mapbox_gl',
              layoutDirection: TextDirection.ltr,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
              onFocus: () => params.onFocusChanged(true),
            );
            controller.addOnPlatformViewCreatedListener(
              params.onPlatformViewCreated,
            );
            controller.addOnPlatformViewCreatedListener(
              onPlatformViewCreated,
            );
-            controller.create();
            return controller;
          },
        );
-      } else {
-        return AndroidView(
-          viewType: 'plugins.flutter.io/mapbox_gl',
-          onPlatformViewCreated: onPlatformViewCreated,
-          gestureRecognizers: gestureRecognizers,
-          creationParams: creationParams,
-          creationParamsCodec: const StandardMessageCodec(),
-        );
-      }
    } else if (defaultTargetPlatform == TargetPlatform.iOS) {
      return UiKitView(
        viewType: 'plugins.flutter.io/mapbox_gl',
        onPlatformViewCreated: onPlatformViewCreated,
        gestureRecognizers: gestureRecognizers,
        creationParams: creationParams,
        creationParamsCodec: const StandardMessageCodec(),
      );
    }
    return Text(
        '

0
投票

我也正在受这个苦。我更改为

initExpensiveAndroidView
,UI 滚动变得平滑,但我在某些 Android 设备上出现本机崩溃..主要是在 Android 10 上。

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