Skip to content

Fixed _controller and MediaQuery#225

Open
JohanScheepers wants to merge 1 commit intothingsboard:masterfrom
JohanScheepers:TbAppBar
Open

Fixed _controller and MediaQuery#225
JohanScheepers wants to merge 1 commit intothingsboard:masterfrom
JohanScheepers:TbAppBar

Conversation

@JohanScheepers
Copy link

@JohanScheepers JohanScheepers commented Mar 3, 2026

Issues with SuperTooltip in

tb_app_bar.dart

1. _controller on a non-StatefulWidget (Critical Bug)

Line 38:

final _controller = SuperTooltipController();

TbAppBar
is a HookConsumerWidget — it behaves like a stateless widget. Declaring _controller as an instance field means:

A new controller is created every time a new

TbAppBar
instance is created, but since HookConsumerWidget is stateless, Flutter may rebuild and discard widget instances often.
Even though the object is final, the Widget itself has no lifecycle management. The controller is never disposed, so it leaks resources (an overlay entry can remain open, listeners aren't cleaned up).
If the widget rebuilds with a new instance, the old controller reference held by the tooltip becomes stale, causing the showTooltip() call on line 164 to potentially affect a dead controller.
Fix: Use useMemoized (since this is a HookConsumerWidget) inside

build
so the controller is created once per widget instance and respects the hook lifecycle:

@override
Widget build(BuildContext context, WidgetRef ref) {
 final controller = useMemoized(SuperTooltipController.new); // ✅ Correct
 // ...
 // Pass controller down to buildTooltip(text, context, controller)
}

And update buildTooltip to accept the controller as a parameter:

Widget buildTooltip(Text text, BuildContext context, SuperTooltipController controller)

2: buildTooltip

Uses Instance Field Passed via Two Call Sites
Because _controller is a class field, it's shared between all calls to

buildTooltip(...)
— both on line 97 (when the title is directly a Text) and line 106 (when iterating the columns). If a title with a Column has multiple Text children, all their tooltips share the same controller, meaning showing one tooltip may interfere with another.

3: MediaQueryData.fromView is Deprecated

Line 125:

final padding = MediaQuery.of(context).padding.top;

MediaQueryData.fromView was deprecated in Flutter 3.7. The recommended replacement is:

final padding = MediaQuery.of(context).padding.top;
# Severity Location Issue
1 Critical Line 38 SuperTooltipController declared as a field on a stateless widget — leaks resources and may become stale
2 Moderate Lines 97, 106 All tooltip instances share one controller — may conflict if multiple tooltips exist
3 Minor Line 125 MediaQueryData.fromView is deprecated; use MediaQuery.paddingOf(context).top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant