jame
jame

Reputation: 132

Flutter How to pass touch event through a platform view to another

I have an app with two platform view one of these is a doodle view and another is webview, below is my code

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(),
              )
            ],
          ),
        ),
      ),
    );
  }

when I set UiKitView hitTestBehavior: PlatformViewHitTestBehavior.transparent,the bottom Listener will print web down, web up ..., but the WebView can not receive touch event, I can't input and click button in html. the GLView is just a OpenGL View to render doodle.


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.

Upvotes: 3

Views: 6109

Answers (1)

Pavan
Pavan

Reputation: 170

check this out https://stackoverflow.com/a/55431380

Wrapping a widget with IgnorePointer makes all touch events for the widget pass through to the widget underneath.

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(),
               ),
             ),
            ],
          ),

Upvotes: 8

Related Questions