Home > Net >  Flutter: Is there a VSCode "when clause" for the widget inspector?
Flutter: Is there a VSCode "when clause" for the widget inspector?

Time:09-28

I'd like shift cmd i to toggle Inspect Widget (in other words, when inspecting a widget in the DevTools Widget Inspector page, the shortcut should run Cancel Widget Inspection).

I need a "when clause" for my keyboard bindings to detect this, like

    {
        "key": "shift cmd i",
        "command": "flutter.inspectWidget"
    },
    {
        "key": "shift cmd i",
        "command": "flutter.cancelInspectWidget"
        "when": "INSPECTING_A_WIDGET" // what to put here?
    }

Does it exist? Or more generally, is there code I can search to find all of Flutter's when clauses?

Update:

Following the accepted answer's instructions, the DevTools console showed that dart-code:flutter.isInspectingWidget was enabled. The following keyboard shortcuts now toggle widget inspection:

    {
        "key": "shift cmd i",
        "command": "flutter.inspectWidget"
    },
    {
        "key": "shift cmd i",
        "command": "flutter.cancelInspectWidget",
        "when": "dart-code:flutter.isInspectingWidget"
    }

CodePudding user response:

  • Put the focus in the element
  • Execute: Help | Toggle Developer Tools
  • Execute command: Developer: Inspect Context Keys
  • inspect the console (press Escape to open it) and see if there is a context key that is true when the element has focus. In your case, dart-code:flutter.isInspectingWidget should be true.
  • Related