Fixed _controller and MediaQuery#225
Open
JohanScheepers wants to merge 1 commit intothingsboard:masterfrom
Open
Fixed _controller and MediaQuery#225JohanScheepers wants to merge 1 commit intothingsboard:masterfrom
JohanScheepers wants to merge 1 commit intothingsboard:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues with SuperTooltip in
tb_app_bar.dart
1. _controller on a non-StatefulWidget (Critical Bug)
Line 38:
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:
And update buildTooltip to accept the controller as a parameter:
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:
MediaQueryData.fromView was deprecated in Flutter 3.7. The recommended replacement is: