Skip to content

Overlay painting with 'hole' doesn't work on web #149743

Closed as duplicate
Closed as duplicate

Description

@geokala

Steps to reproduce

I've put a repro up in https://github.com/geokala/flutterpainterbug

When one tries to create an overlay with a painted 'hole' (a lighter area where one can see through the overlay, as in https://pub.dev/packages/app_tutorial), there is no lighter area appearing on web browsers in my testing.
I've not observed any obvious errors being reported.

Expected results

When running the app from the linked repo, either on desktop or web, and clicking 'Show transparency with a hole', most of the screen should be dark with one lighter hole.

Actual results

On desktop this seems to work.
On web (chromium+firefox), there is only the dark overlay.

Code sample

Code sample https://github.com/geokala/flutterpainterbug

Screenshots or Video

Will be attached shortly.

Logs

Logs
flutter create --platforms=linux .
flutter run lib/main.dart -d linux
flutter run lib/main.dart -d web-server

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.1, on Ubuntu 22.04.4 LTS 6.5.0-35-generic, locale en_GB.UTF-8)
    • Flutter version 3.22.1 on channel stable at /tmp/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a14f74ff3a (2 weeks ago), 2024-05-22 11:08:21 -0500
    • Engine revision 55eae6864b
    • Dart version 3.4.1
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/talkur/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/talkur/Android/Sdk/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1.1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2023.2)
    • Android Studio at /home/talkur/Android/Sdk/android-studio
    • Flutter plugin version 78.4.1
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.86.2)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.4 LTS 6.5.0-35-generic

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. geokala commented on Jun 5, 2024

    @geokala
    Author

    Screenshot from chromium
    Painterbug-chromium
    Screenshot from firefox
    Painterbug-firefox

    Screenshot of correct behaviour from desktop (linux):
    Painternobug-desktop

  2. added
    in triage
    on Jun 6, 2024
  3. huycozy commented on Jun 6, 2024

    @huycozy
    Member

    Thanks for the report. I can reproduce this. The issue is reproduced with canvaskit renderer only. With HTML renderer, there is an error combinePaths not implemented in HTML renderer.

    I bring the main sample code from your GitHub repository here so that others can look at it quickly:

    Sample code
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          title: 'Painterbug?',
          home: MyHomePage(title: 'Painterbug?'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
    
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: Theme.of(context).colorScheme.inversePrimary,
            title: Text(widget.title),
          ),
          body: Center(child: Column(
            children: [
              ElevatedButton(
                onPressed: showBug,
                child: const Text('Show transparency with a hole.'),
              ),
            ],
          )),
        );
      }
    
      void showBug() {
        final size = MediaQuery.of(context).size;
        OverlayState overlayState = Overlay.of(context);
    
        overlayState.insert(
          OverlayEntry(
            builder: (context) {
              return Scaffold(
                backgroundColor: Colors.transparent,
                body: Stack(
                  children: [
                    CustomPaint(
                      size: size,
                      painter: HolePainter(
                        dx: 300.0,
                        dy: 300.0,
                        width: 56.0,
                        height: 56.0,
                        borderRadius: const Radius.circular(10.0),
                      )
                    ),
                  ],
                ),
              );
            },
          ),
        );
      }
    }
    
    
    class HolePainter extends CustomPainter {
      final double dx;
      final double dy;
      final double width;
      final double height;
      final Radius borderRadius;
    
      HolePainter({
        required this.dx,
        required this.dy,
        required this.width,
        required this.height,
        required this.borderRadius,
      });
    
      @override
      void paint(Canvas canvas, Size size) {
        final paint = Paint()..color = Colors.black.withOpacity(0.6);
        canvas.drawPath(
            Path.combine(
              PathOperation.difference,
              Path()..addRect(Rect.fromLTWH(0, 0, size.width, size.height)),
              Path()
                ..addOval(Rect.fromCircle(
                    center: Offset(dx, dy), radius: width))
                ..close(),
            ),
            paint);
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return false;
      }
    }
    
    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.22.1, on macOS 14.1 23B74 darwin-x64, locale en-VN)
        • Flutter version 3.22.1 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision a14f74ff3a (13 days ago), 2024-05-22 11:08:21 -0500
        • Engine revision 55eae6864b
        • Dart version 3.4.1
        • DevTools version 2.34.3
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode15.3.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.3)
        • 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
        • android-studio-dir = /Applications/Android Studio.app/
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    
    [✓] VS Code (version 1.89.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.90.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 14.1 23B74 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 125.0.6422.142
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.23.0-13.0.pre.117, on macOS 14.1 23B74 darwin-x64, locale en-VN)
        • Flutter version 3.23.0-13.0.pre.117 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d3a273971c (44 minutes ago), 2024-06-05 21:45:25 -0400
        • Engine revision f51e0ad3ab
        • Dart version 3.5.0 (build 3.5.0-226.0.dev)
        • DevTools version 2.36.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode15.3.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.3)
        • 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
        • android-studio-dir = /Applications/Android Studio.app/
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    
    [✓] VS Code (version 1.89.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.90.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 14.1 23B74 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 125.0.6422.142
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  4. added
    framework
    platform-web
    has reproducible steps
    team-web
    found in release: 3.22
    found in release: 3.23
    and removed
    in triage
    on Jun 6, 2024
  5. geokala commented on Jun 6, 2024

    @geokala
    Author

    @huycozy Great, good to hear.
    I was doing some more poking around yesterday and did find that one of the three stages of the app_tutorial example successfully paints a 'hole'.
    Said example can be found here: https://github.com/aikenahac/app_tutorial/tree/master/example
    On my system, the third stage paints a 'hole' at the top left of the screen, but even poking more around that, I couldn't figure why that one worked and the others (and simplified example) didn't.

  6. LimaneGaya commented on Jun 6, 2024

    @LimaneGaya
    Contributor

    I have been tinkering with this and i found out that:

    Path.combine(PathOperation.difference,
                Path()..addRect(Rect.fromLTWH(dx - 200, dy - 200, 400, 400)), 
                Path()
                ..addOval(Rect.fromCircle(center: Offset(dx, dy-200), radius: 1))  //1
                ..addOval(Rect.fromCircle(center: Offset(dx, dy), radius: 50))       //2
                ..addOval(Rect.fromCircle(center: Offset(dx, dy-198), radius: 1))  //3
                ..addOval(Rect.fromCircle(center: Offset(dx, dy+200), radius: 25))  //4

    As long as one of them intersect the border the others will be visible

    first intersects first does't
    works notworks

    This works

    Path.combine(PathOperation.difference,
                Path()..addRect(Rect.fromLTWH(dx - 200, dy - 200, 400, 400)), 
                Path()
                ..addOval(Rect.fromCircle(center: Offset(dx, dy-200), radius: 1))
                ..addOval(Rect.fromCircle(center: Offset(dx, dy), radius: 50))        
                ,),
            paint);

    This doesn't

    Path.combine(PathOperation.difference,
               Path()..addRect(Rect.fromLTWH(dx - 200, dy - 200, 400, 400)), 
               Path()
               ..addOval(Rect.fromCircle(center: Offset(dx, dy-198), radius: 1))
               ..addOval(Rect.fromCircle(center: Offset(dx+150, dy-150), radius: 25))  
               ..addOval(Rect.fromCircle(center: Offset(dx, dy), radius: 50))
               ,),
           paint);

    @geokala until this issue is fixed you could try this change by adding a small circle at one corner and see if it works (it works for me) like i put bellow.

    code
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          title: 'Painterbug?',
          home: MyHomePage(title: 'Painterbug?'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
    
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: Theme.of(context).colorScheme.inversePrimary,
            title: Text(widget.title),
          ),
          body: Center(child: Column(
            children: [
              ElevatedButton(
                onPressed: showBug,
                child: const Text('Show transparency with a hole.'),
              ),
            ],
          )),
        );
      }
    
      void showBug() {
        final size = MediaQuery.of(context).size;
        OverlayState overlayState = Overlay.of(context);
    
        overlayState.insert(
          OverlayEntry(
            builder: (context) {
              return Scaffold(
                backgroundColor: Colors.transparent,
                body: Stack(
                  children: [
                    CustomPaint(
                      size: size,
                      painter: HolePainter(
                        dx: 300.0,
                        dy: 300.0,
                        width: 56.0,
                        height: 56.0,
                        borderRadius: const Radius.circular(10.0),
                      )
                    ),
                  ],
                ),
              );
            },
          ),
        );
      }
    }
    
    
    class HolePainter extends CustomPainter {
      final double dx;
      final double dy;
      final double width;
      final double height;
      final Radius borderRadius;
    
      HolePainter({
        required this.dx,
        required this.dy,
        required this.width,
        required this.height,
        required this.borderRadius,
      });
    
      @override
      void paint(Canvas canvas, Size size) {
        final paint = Paint()..color = Colors.black.withOpacity(0.6);
        canvas.drawPath(
            Path.combine(
              PathOperation.difference,
              Path()..addRect(Rect.fromLTWH(0, 0, size.width, size.height)),
              Path()
              ..addOval(Rect.fromCircle(center: const Offset(0, 0), radius: 1))
              ..addOval(Rect.fromCircle(center: Offset(dx, dy), radius: 20))
              ,
            ),
            paint);
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return false;
      }
    }
  7. geokala commented on Jun 7, 2024

    @geokala
    Author

    @LimaneGaya Thanks for the workaround. I'm buried in something else today but I'll give that a try likely monday and let you know!

  8. geokala commented on Jun 10, 2024

    @geokala
    Author

    @LimaneGaya That does indeed appear to work for me as well, on both the POC code and on the original app_tutorial code too.

  9. added
    e: web_canvaskit
    P2
    triaged-web
    e: web_skwasm
    on Jun 13, 2024
  10. zhxst commented on Jul 5, 2024

    @zhxst

    Same issue here on Android.

  11. sma commented on Jan 22, 2025

    @sma

    I think, this is the same issue as #124675.

  12. github-actions commented on Nov 21, 2026

    @github-actions

    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.

  13. locked as resolved and limited conversation to collaborators on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2e: web_canvaskite: web_skwasmfound in release: 3.22found in release: 3.23frameworkhas reproducible stepsplatform-webteam-webtriaged-web

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions