gpt4 book ai didi

Flutter 如何将触摸事件通过一个平台 View 传递到另一个平台 View

转载 作者:行者123 更新时间:2023-12-02 03:03:02 27 4
gpt4 key购买 nike

我有一个具有两个平台 View 的应用程序,其中一个是涂鸦 View ,另一个是 WebView ,下面是我的代码

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('test'),
),
body: BlocProvider<CourseDocBloc>(
create: (context) => CourseDocBloc(),
child: Container(
height: double.infinity,
child: Stack(
children: <Widget>[
Listener(
child: WebView(
initialUrl: 'https://google.com',
javascriptMode: JavascriptMode.unrestricted,
onPageStarted: (url) {
print('start load');
},
onPageFinished: (url) {
print('load finished');
},
),
onPointerDown: (e) => {print('web down')},
onPointerUp: (e) => {print('web up')},
),
UiKitView(
viewType: 'GLView',
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
onPlatformViewCreated: (_) => created(),
)
],
),
),
),
);
}

当我设置UiKitView hitTestBehavior: PlatformViewHitTestBehavior.transparent时,底部Listener会打印web down, web up ... ,但是WebView无法接收触摸事件,我无法在html中输入和单击按钮。 GLView 只是一个用于渲染涂鸦的 OpenGL View 。


flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.14.6 18G2022, locale zh-Hans-CN)

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Ultimate Edition (version 2019.1.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.40.2)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

最佳答案

看看这个 https://stackoverflow.com/a/55431380

使用 IgnorePointer 包装小部件会使该小部件的所有触摸事件传递到下面的小部件。

child: Stack(
children: <Widget>[
Listener(
child: WebView(
initialUrl: 'https://google.com',
javascriptMode: JavascriptMode.unrestricted,
onPageStarted: (url) {
print('start load');
},
onPageFinished: (url) {
print('load finished');
},
),
onPointerDown: (e) => {print('web down')},
onPointerUp: (e) => {print('web up')},
),
IgnorePointer(
child: UiKitView(
viewType: 'GLView',
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
onPlatformViewCreated: (_) => created(),
),
),
],
),

关于Flutter 如何将触摸事件通过一个平台 View 传递到另一个平台 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59657041/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com