File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -529,7 +529,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
529529  /// Returns `false`  when the tooltip shouldn't be shown or when the tooltip 
530530  /// was already visible. 
531531bool  ensureTooltipVisible () {
532-     if  (! _visible) {
532+     if  (! _visible  ||   ! mounted ) {
533533      return  false ;
534534    }
535535    _showTimer? .cancel ();
Original file line number Diff line number Diff line change @@ -1053,6 +1053,37 @@ void main() {
10531053    gesture =  null ;
10541054  });
10551055
1056+   testWidgets ('Calling ensureTooltipVisible on an unmounted TooltipState returns false' , (WidgetTester  tester) async  {
1057+     // Regression test for https://github.com/flutter/flutter/issues/95851 
1058+     await  tester.pumpWidget (
1059+       const  MaterialApp (
1060+         home:  Center (
1061+           child:  Tooltip (
1062+             message:  tooltipText,
1063+             child:  SizedBox (
1064+               width:  100.0 ,
1065+               height:  100.0 ,
1066+             ),
1067+           ),
1068+         ),
1069+       ),
1070+     );
1071+ 
1072+     final  TooltipState  tooltipState =  tester.state (find.byType (Tooltip ));
1073+     expect (tooltipState.ensureTooltipVisible (), true );
1074+ 
1075+     // Remove the tooltip. 
1076+     await  tester.pumpWidget (
1077+       const  MaterialApp (
1078+         home:  Center (
1079+           child:  SizedBox .shrink (),
1080+         ),
1081+       ),
1082+     );
1083+ 
1084+     expect (tooltipState.ensureTooltipVisible (), false );
1085+   });
1086+ 
10561087  testWidgets ('Tooltip shows/hides when hovered' , (WidgetTester  tester) async  {
10571088    const  Duration  waitDuration =  Duration .zero;
10581089    TestGesture ?  gesture =  await  tester.createGesture (kind:  PointerDeviceKind .mouse);
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments