Unverified Commit 399a649e authored by Bruno Leroux's avatar Bruno Leroux Committed by GitHub

Fix TooltipState null check error (#106330)

parent 61b3b399
...@@ -529,7 +529,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { ...@@ -529,7 +529,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
/// Returns `false` when the tooltip shouldn't be shown or when the tooltip /// Returns `false` when the tooltip shouldn't be shown or when the tooltip
/// was already visible. /// was already visible.
bool ensureTooltipVisible() { bool ensureTooltipVisible() {
if (!_visible) { if (!_visible || !mounted) {
return false; return false;
} }
_showTimer?.cancel(); _showTimer?.cancel();
......
...@@ -1053,6 +1053,37 @@ void main() { ...@@ -1053,6 +1053,37 @@ void main() {
gesture = null; gesture = null;
}); });
testWidgets('Calling ensureTooltipVisible on an unmounted TooltipState returns false', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/95851
await tester.pumpWidget(
const MaterialApp(
home: Center(
child: Tooltip(
message: tooltipText,
child: SizedBox(
width: 100.0,
height: 100.0,
),
),
),
),
);
final TooltipState tooltipState = tester.state(find.byType(Tooltip));
expect(tooltipState.ensureTooltipVisible(), true);
// Remove the tooltip.
await tester.pumpWidget(
const MaterialApp(
home: Center(
child: SizedBox.shrink(),
),
),
);
expect(tooltipState.ensureTooltipVisible(), false);
});
testWidgets('Tooltip shows/hides when hovered', (WidgetTester tester) async { testWidgets('Tooltip shows/hides when hovered', (WidgetTester tester) async {
const Duration waitDuration = Duration.zero; const Duration waitDuration = Duration.zero;
TestGesture? gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); TestGesture? gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment