-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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!