欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

【Flutter】调用AndroidView 多指滑动报错问题

程序员文章站 2022-03-03 21:48:49
环境:android8.1 以及 android 5.0(暂时推测为android8.1以下因为android10并没有此问题)flutter 1.22.0+使用AndroidView包了一下原生的高德地图,在地图上3+个手指头以上触摸屏幕则会爆以下错误。E/flutter ( 4633): #0 _AndroidMotionEventConverter.toAndroidMotionEventpackage:flutter/…/services/platform_views....

环境:

android8.1 以及 android 5.0(暂时推测为android8.1以下因为android10并没有此问题)

flutter 1.22.0+

使用AndroidView包了一下原生的高德地图,在地图上3+个手指头以上触摸屏幕则会爆以下错误。 

E/flutter ( 4633): #0      _AndroidMotionEventConverter.toAndroidMotionEvent
package:flutter/…/services/platform_views.dart:596
E/flutter ( 4633): #1      AndroidViewController.dispatchPointerEvent
package:flutter/…/services/platform_views.dart:864
E/flutter ( 4633): #2      _PlatformViewGestureRecognizer.handleEvent
package:flutter/…/rendering/platform_view.dart:535
E/flutter ( 4633): #3      PointerRouter._dispatch
package:flutter/…/gestures/pointer_router.dart:77
E/flutter ( 4633): #4      PointerRouter._dispatchEventToRoutes.<anonymous closure>
package:flutter/…/gestures/pointer_router.dart:122
E/flutter ( 4633): #5      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter ( 4633): #6      PointerRouter._dispatchEventToRoutes
package:flutter/…/gestures/pointer_router.dart:120
E/flutter ( 4633): #7      PointerRouter.route
package:flutter/…/gestures/pointer_router.dart:106
E/flutter ( 4633): #8      GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:358
E/flutter ( 4633): #9      GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:338
E/flutter ( 4633): #10     RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:267
E/flutter ( 4633): #11     GestureBinding._handlePointerEvent

过程:初步怀疑是高德地图的问题。但是在注释掉地图使用ScrollView测试时发现也爆此问题所以怀疑是收拾冲突引起的,于是在AndroidView外用GestureDetector进行包裹,结果能用了,不报错了(onTapDown必须赋值,要不也会报错)。

@override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTapDown: (event) {}, //虽然看着没啥用 但是解决 多指滑动报错问题 (android 8.1以下)
      child: AndroidView(
        viewType: 'plugin/aMapView',
        onPlatformViewCreated: (id) async {
          this.id = id;
          _channel = new MethodChannel('plugin/aMapView_$id');

          _channel.setMethodCallHandler(handelCallMethod);
          final bundle = await android_os_Bundle.create();

          _channel.invokeMethod("onCreate", {"bundle": bundle.refId});
        },
        creationParamsCodec: const StandardMessageCodec(),
        creationParams: {"zoomLevel": widget.zoomLevel},
      ),
    );
  }

 

本文地址:https://blog.csdn.net/weixin_39370093/article/details/110127852

相关标签: Flutter