Skip to content

[BUG] Tooltip calls build when mouse enters/leaves Flutter window #117627

Closed

Description

@asmith20002

Bug Summary

When mouse enters/leaves the flutter app window, Tooltip widget rebuilds its child unnecessarily. The mouse pointer doesn't even need to enter the Tooltip area, just by entering or leaving the app window, all Tooltip widgets rebuild their children.

Demonstration

Sample code is provided below. There's a print() in the builder which is the child of the Tooltip. Each time mouse enters or leaves the app, the print() is getting called and logs "rebuilding!". (My original code had TweenAnimationBuilder and it was repeating the animation over and over but I've stripped it down to a simple builder to demonstrate.)

25.12.2022_11.40.20_REC.mp4

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 MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Tooltip bug'),
    );
  }
}

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(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          decoration:
              BoxDecoration(border: Border.all(width: 1, color: Colors.blue)),
          child: SizedBox(
            height: 100,
            width: 100,
            child: Tooltip(
              message: 'Some label',
              child: Builder(
                builder: (BuildContext context) {
                  // ignore: avoid_print
                  print('rebuilding!');
                  return const Icon(
                    Icons.abc_outlined,
                    size: 100,
                    color: Colors.red,
                  );
                },
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.22621.963], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.6)
[√] Android Studio (version 2021.2)
[√] VS Code, 64-bit edition (version 1.74.1)
[√] Connected device (4 available)
[√] HTTP Host Availability

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Dec 26, 2022
  2. huycozy commented on Dec 26, 2022

    @huycozy
    Member

    @asmith20002 thanks for your report. This issue is reproducible on the latest stable and master channels. It seems only to happen on desktop app as below since I can't see the issue on Web app.

    MacOS Web
    ❌ ✅

    ✅: No Issue ❌: Issue reproduced

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.3.10, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.3.10 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 135454af32 (13 hours ago), 2022-12-15 07:36:55 -0800
        • Engine revision 3316dd8728
        • Dart version 2.18.6
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, 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.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14B47b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.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
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    
    [✓] 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.73.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.54.0
    
    [✓] Connected device (3 available)
        • SM T225 (mobile) • R9JT3004VRJ • android-arm64  • Android 12 (API 31)
        • macOS (desktop)  • macos       • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome      • web-javascript • Google Chrome 108.0.5359.124
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.7.0-13.0.pre.68, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.7.0-13.0.pre.68 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 239f80ed6c (6 hours ago), 2022-12-25 14:48:16 -0500
        • Engine revision 3ae55014ff
        • Dart version 3.0.0 (build 3.0.0-63.0.dev)
        • DevTools version 2.20.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 31.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, 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.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14B47b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.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
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    
    [✓] 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.74.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.56.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.124
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    a: mouseIssues related to using a mouse or mouse support
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Dec 26, 2022
  4. added
    P2Important issues not at the top of the work list
    on Jan 5, 2023
  5. asmith20002 commented on Jan 26, 2023

    @asmith20002
    Author

    #119199 thanks for the fix.

    Moreover on this issue:
    If there are CustomPaints in the code, those CustomPaint builders get called along with tooltips children. Again it doesn't matter if the CustomPaint is inside Tooltip or not. Even the ones outside and completely unrelated get rebuilt again. (shouldRepaint is set to false)

    Same sample code with CustomPaint added

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Tooltip bug'),
        );
      }
    }
    
    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(
            title: Text(widget.title),
          ),
          body: Center(
            child: Container(
              decoration: BoxDecoration(
                border: Border.all(width: 1, color: Colors.blue),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  CustomPaint(
                    painter: MyCustomPaint(),
                    child: const SizedBox(
                      height: 100,
                      width: 100,
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 100,
                    child: Tooltip(
                      message: 'Some label',
                      child: Builder(
                        builder: (BuildContext context) {
                          // ignore: avoid_print
                          print('rebuilding!');
                          return const Icon(
                            Icons.abc_outlined,
                            size: 100,
                            color: Colors.red,
                          );
                        },
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
    
    class MyCustomPaint extends CustomPainter {
      @override
      void paint(Canvas canvas, Size size) {
        print('rebuilding paint!');
    
        canvas.drawRect(
            Rect.fromLTWH(0, 0, 100, 100), Paint()..color = Colors.blue);
      }
    
      @override
      bool shouldRepaint(covariant CustomPainter oldDelegate) {
        return false;
      }
    }
    
    
  6. cliftonlabrum commented on Feb 1, 2023

    @cliftonlabrum

    Just ran into this same issue. This is particularly noticeable when your widget has an Image.memory() widget in it since it will redraw the image and it looks like it's reloading the picture on each mouse reentry. 😅

  7. github-actions commented on Jun 8, 2023

    @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.

  8. locked as resolved and limited conversation to collaborators on Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopa: mouseIssues related to using a mouse or mouse supportfound in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions