Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointerInterceptor disappears behind Map after repaint (CanvasKit) #104970

Closed
stevendz opened this issue May 30, 2022 · 10 comments
Closed

PointerInterceptor disappears behind Map after repaint (CanvasKit) #104970

stevendz opened this issue May 30, 2022 · 10 comments
Labels
c: rendering UI glitches reported at the engine/skia rendering level e: web_canvaskit CanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Web found in release: 3.0 Found to occur in 3.0 found in release: 3.1 Found to occur in 3.1 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pointer_interceptor A widget to prevent clicks from being swallowed by underlying HtmlElementViews on the web P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically

Comments

@stevendz
Copy link

stevendz commented May 30, 2022

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Toggle PointerInterceptors or Map

Expected results:
Both Elements (red and green) stay on top of the map

Actual results:
The PointerInterceptor (red/left) will be gone but the plain HTMLElement (green/right) will still be on top.

So why the PointerInterceptor is behind the Map and the plain HTMLElement will stay in front of it?

Code sample
dependencies:
  google_maps: any
  pointer_interceptor: any
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:google_maps/google_maps.dart';

void main() => runApp(const MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  State<MyApp> createState() => _MyAppState();
}

const String viewTypeInterceptor = 'interceptor';

class _MyAppState extends State<MyApp> {
  bool _isBackgroundVisible = true;
  bool _isInterceptorVisible = true;

  @override
  void initState() {
    super.initState();
    // ignore: undefined_prefixed_name, avoid_dynamic_calls
    ui.platformViewRegistry.registerViewFactory(
      viewTypeInterceptor,
      (int viewId) => DivElement()
        ..style.width = "100%"
        ..style.height = "100%"
        ..style.backgroundColor = 'rgba(0, 255, 0, 0.5)',
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          children: [
            TextButton(
                onPressed: () => setState(() => _isInterceptorVisible = !_isInterceptorVisible),
                child: const Text('Toggle Interceptors', style: TextStyle(color: Colors.black))),
            TextButton(
                onPressed: () => setState(() => _isBackgroundVisible = !_isBackgroundVisible),
                child: const Text('Toggle Background', style: TextStyle(color: Colors.black))),
          ],
        ),
      ),
      body: Stack(
        children: [
          const SizedBox.expand(),
          Visibility(visible: _isBackgroundVisible, child: getMap()),
          PointerInterceptor(
            debug: true,
            intercepting: _isInterceptorVisible,
            child: const SizedBox(height: 300, width: 300),
          ),
          Positioned(
            right: 0,
            child: Interceptor(isVisible: _isInterceptorVisible),
          ),
        ],
      ),
    );
  }

  Widget getMap() {
    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory('map', (_) {
      final div = DivElement()
        ..id = 'map'
        ..style.width = "100%"
        ..style.height = "100%"
        ..style.border = 'none';

      Marker(MarkerOptions()
        ..position = LatLng(1.3521, 103.8198)
        ..map = GMap(
          div,
          MapOptions()
            ..zoom = 10
            ..center = LatLng(1.3521, 103.8198),
        ));

      return div;
    });

    return const HtmlElementView(viewType: 'map');
  }
}

class Interceptor extends StatelessWidget {
  const Interceptor({required this.isVisible, Key? key}) : super(key: key);
  final bool isVisible;
  @override
  Widget build(BuildContext context) {
    if (!isVisible) return const SizedBox(height: 300, width: 300);
    return Stack(
      children: const [
        Positioned.fill(child: HtmlElementView(viewType: viewTypeInterceptor)),
        SizedBox(height: 300, width: 300),
      ],
    );
  }
}
Logs
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-arm, locale en-GB)
    • Flutter version 2.10.5 at /Users/stevendzionara/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (6 weeks ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/stevendzionara/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Users/stevendzionara/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8309675/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Users/stevendzionara/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8309675/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.3)
    • IntelliJ at /Users/stevendzionara/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 66.0.3
    • Dart plugin version 213.7371

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.3)
    • IntelliJ at /Users/stevendzionara/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.7172.25/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.3.1 21E258 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Screen.Recording.2022-05-30.at.15.51.03.mov
@stevendz stevendz changed the title PointerInterceptor is behind Map after repaint PointerInterceptor disappears behind Map after repaint May 30, 2022
@huycozy huycozy added the in triage Presently being triaged by the triage team label May 31, 2022
@huycozy
Copy link
Member

huycozy commented May 31, 2022

Hi. Thank you for reporting this. This issue is reproducible on the latest stable and master channels with provided sample code and using canvaskit renderer.

For the html renderer, the issue is not reproducible.

Demo - HTML renderer
104970_html.mp4
Screenshot inspector - PointerInterceptor is not rendered

Screen Shot 2022-05-31 at 11 00 23

flutter doctor -v
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.2.1 21D62 darwin-x64, locale en-VN)
    • Flutter version 3.0.1 at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (8 hours ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7042882/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] Android Studio
    • Android Studio at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-1/203.7185775/Android Studio
      Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.67.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (3 available)
    • iPhone 13 (mobile) • 2526BC1A-435D-4B08-B99C-44B928F2517B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 12.2.1 21D62 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[✓] Flutter (Channel master, 3.1.0-0.0.pre.1013, on macOS 12.2.1 21D62 darwin-x64, locale en-VN)
    • Flutter version 3.1.0-0.0.pre.1013 at /Users/huynq/Documents/GitHub/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 1bf6e0871c (81 minutes ago), 2022-05-30 22:03:11 -0400
    • Engine revision a4d7b6b042
    • Dart version 2.18.0 (build 2.18.0-152.0.dev)
    • DevTools version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7042882/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[!] Android Studio
    • Android Studio at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-1/203.7185775/Android Studio
      Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.67.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (4 available)
    • Pixel 3a (mobile)            • 964AY0WL20                           • android-arm64  • Android 12 (API 32)
    • iPad Pro (9.7-inch) (mobile) • 18AFB65F-7639-4B97-86BD-2A60F1B99BBC • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4
      (simulator)
    • macOS (desktop)              • macos                                • darwin-x64     • macOS 12.2.1 21D62 darwin-x64
    • Chrome (web)                 • chrome                               • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

@huycozy huycozy added p: first party platform-web Web applications specifically package flutter/packages repository. See also p: labels. c: rendering UI glitches reported at the engine/skia rendering level e: web_canvaskit CanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Web has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pointer_interceptor A widget to prevent clicks from being swallowed by underlying HtmlElementViews on the web found in release: 3.0 Found to occur in 3.0 found in release: 3.1 Found to occur in 3.1 and removed in triage Presently being triaged by the triage team labels May 31, 2022
@stevendz stevendz changed the title PointerInterceptor disappears behind Map after repaint PointerInterceptor disappears behind Map after repaint (CanvasKit) May 31, 2022
@yjbanov yjbanov added the P2 Important issues not at the top of the work list label Jun 2, 2022
@ozz-rjq
Copy link

ozz-rjq commented Jun 8, 2022

having the same issue

@Manatho
Copy link

Manatho commented Jun 8, 2022

Same here with Mapbox-gl

@digiecho
Copy link

any update on this?

@prasant10050
Copy link

Having the same issue. When google map or HtmlElementView is used in combination with pointer interceptor and stack the application running on the web crashes with the following assertion error:
Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/canvaskit/embedded_views.dart:409:12
_context.pictureRecorders.length == _overlays.length
is not true
Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/canvaskit/embedded_views.dart:609:12
_overlays.length == viewsNeedingOverlays.length
is not true

@dab246
Copy link

dab246 commented Apr 3, 2023

any update for this?

@ditman
Copy link
Member

ditman commented Apr 28, 2023

I checked this again and I cannot reproduce the original issue (2022 comments), see this code, I tried to keep it as close to the original as possible (but I was getting errors compiling the original example):

(Click to see code)
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
import 'package:pointer_interceptor/pointer_interceptor.dart';

void main() { 
  runApp(const MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  State<MyApp> createState() => _MyAppState();
}

const String viewTypeInterceptor = 'interceptor';
const String viewTypeBackground = 'background';

class _MyAppState extends State<MyApp> {
  bool _isBackgroundVisible = true;
  bool _isInterceptorVisible = true;

  @override
  void initState() {
    super.initState();
    // ignore: undefined_prefixed_name, avoid_dynamic_calls
    ui.platformViewRegistry.registerViewFactory(
      viewTypeInterceptor,
      (int viewId) => DivElement()
        ..addEventListener('click', (event) => window.console.log('Clicked on $viewTypeInterceptor $viewId'))
        ..id = 'interceptor$viewId'
        ..style.width = "100%"
        ..style.height = "100%"
        ..style.backgroundColor = '#0F0',
    );

    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory(viewTypeBackground, (int viewId) {
      return DivElement()
        ..addEventListener('click', (event) => window.console.log('Clicked on $viewTypeBackground $viewId'))
        ..id = 'bluebg$viewId'
        ..style.width = "100%"
        ..style.height = "100%"
        ..style.backgroundColor = '#00F';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          children: [
            TextButton(
                onPressed: () => setState(() => _isInterceptorVisible = !_isInterceptorVisible),
                child: const Text('Toggle Interceptors', style: TextStyle(color: Colors.black))),
            TextButton(
                onPressed: () => setState(() => _isBackgroundVisible = !_isBackgroundVisible),
                child: const Text('Toggle Background', style: TextStyle(color: Colors.black))),
          ],
        ),
      ),
      body: Stack(
        children: [
          const SizedBox.expand(),
          Visibility(visible: _isBackgroundVisible, child: getMap()),
          PointerInterceptor(
            debug: true,
            intercepting: _isInterceptorVisible,
            child: const SizedBox(height: 300, width: 300),
          ),
          Positioned(
            right: 0,
            child: Interceptor(isVisible: _isInterceptorVisible),
          ),
        ],
      ),
    );
  }

  Widget getMap() {
    return const HtmlElementView(viewType: viewTypeBackground);
  }
}

class Interceptor extends StatelessWidget {
  const Interceptor({required this.isVisible, Key? key}) : super(key: key);
  final bool isVisible;
  @override
  Widget build(BuildContext context) {
    if (!isVisible) return const SizedBox(height: 300, width: 300);
    return const Stack(
      children: [
        Positioned.fill(child: HtmlElementView(viewType: viewTypeInterceptor)),
        SizedBox(height: 300, width: 300),
      ],
    );
  }
}

Is google maps really needed to reproduce the issue? Or is any solid HTML Element Input enough?


There's another issue here:

Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/canvaskit/embedded_views.dart:609:12
_overlays.length == viewsNeedingOverlays.length is not true

@hterkelsen is looking at that one. It has to do with the stuff flutter web needs to do to layer canvases and platform views correctly.

@pavel604
Copy link

I believe this has been resolved in V3.7, but don't take my word for it...

@ditman
Copy link
Member

ditman commented May 5, 2023

I suspect I fixed this here, but never related it to this issue:

flutter/engine#39506

I'm going to close this as fixed, and if there's still issues, please file a new issue. It'll likely require new reproduction code!

(Looks like the fix will land in the upcoming 3.10 stable)

@ditman ditman closed this as completed May 5, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: rendering UI glitches reported at the engine/skia rendering level e: web_canvaskit CanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Web found in release: 3.0 Found to occur in 3.0 found in release: 3.1 Found to occur in 3.1 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pointer_interceptor A widget to prevent clicks from being swallowed by underlying HtmlElementViews on the web P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically
Projects
None yet
Development

No branches or pull requests