@@ -1090,7 +1090,7 @@ mixin WidgetInspectorService {
10901090 getter: () async => WidgetsBinding .instance.debugShowWidgetInspectorOverride,
10911091 setter: (bool value) {
10921092 if (WidgetsBinding .instance.debugShowWidgetInspectorOverride != value) {
1093- WidgetsBinding .instance.debugShowWidgetInspectorOverride = value ;
1093+ _changeWidgetSelectionMode (value, notifyStateChange : false ) ;
10941094 }
10951095 return Future <void >.value ();
10961096 },
@@ -1633,9 +1633,15 @@ mixin WidgetInspectorService {
16331633 }
16341634
16351635 /// Changes whether widget selection mode is [enabled] .
1636- void _changeWidgetSelectionMode (bool enabled) {
1636+ void _changeWidgetSelectionMode (bool enabled, { bool notifyStateChange = true } ) {
16371637 WidgetsBinding .instance.debugShowWidgetInspectorOverride = enabled;
1638- _postExtensionStateChangedEvent (WidgetInspectorServiceExtensions .show.name, enabled);
1638+ if (notifyStateChange) {
1639+ _postExtensionStateChangedEvent (WidgetInspectorServiceExtensions .show.name, enabled);
1640+ }
1641+ if (! enabled) {
1642+ // If turning off selection mode, clear the current selection.
1643+ selection.currentElement = null ;
1644+ }
16391645 }
16401646
16411647 /// Returns a DevTools uri linking to a specific element on the inspector page.
@@ -3056,7 +3062,7 @@ class InspectorSelection with ChangeNotifier {
30563062 }
30573063 if (currentElement != element) {
30583064 _currentElement = element;
3059- _current = element! .findRenderObject ();
3065+ _current = element? .findRenderObject ();
30603066 notifyListeners ();
30613067 }
30623068 }
0 commit comments