How to use Flutter's Widget Inspector in Visual Studio Code? - visual-studio-code

How do you use the Flutter Widget Inspector introduced in VSCode and now enabled? When I debug the app from the IDE or Terminal, nothing happens when I click on any widget in the iOS simulator. I could not find any info on VSCode from Google.
I am on MacOS Sierra.

As of v2.24, the Dart extension for VS Code has integration with the Dart DevTools. This has much better inspector functionality than the original Inspect Widget command mentioned by stt106's.
With a debugging session active, open the command palette and find the DevTools command.
The first time you run this you'll may be prompted to activate or upgrade.
DevTools will then launch in your browser and connect to your debug session.
There's more info on the functionality of Dart's DevTools in the DevTools docs.

When debugging, run command Flutter: Inspect Widget, then click on the UI/Widget, it will auto lead you to the code which generates the widget. It only works in debugging mode and the command is not available until the app is loaded in debug.

Updated method:
As of Dart Code (VS code extension) version 2.24.0, The 'Flutter: Inspect Widget' command was replaced with DevTools. (at the time of writing this, the latest version is 3.36.0. To get to the Inspect Widget from the command pallet with >Flutter: Open DevTools or >Dart: Open DevTools, requires several steps.
Here's a quicker way:
Click the debug (bug) button from the side menu and Select Run and Debug or press f5
The Widget inspector will open automatically.
Screenshot of emulator using the Flutter Widget inspector

Related

Flutter application is running in emulator but Flutter Widget Inspector is not displaying

I am running my flutter app successfully on my emulator. However, I need the use of the Widget Inspector for testing purposes.
To run my app I use the following:
flutter run --flavor dev -t lib/main_prod.dart
However, when I use the palette to bring up the "Open DevTools" I end up getting what is shown in the image
I've run flutter clean before running my app and it still didn't work.
Please help!
Never mind, I figured it out.
I was looking for the typical pop-up tool bar and overlooked this:
Simply pressing "h" for "List all available interactive commands." brought up a more comprehensive list with the option for an inspector:
Pressing "v" to open the flutter tools here works.

enable a flutter inspector shortcut along with other debug shortcuts in VSCode

How can we enable and disable the flutter inspector shortcut along with other debug shortcuts in VSCode.
You can use the dart. showDevToolsDebugToolBarButtons setting to control this.
Although if the Inspector button has disappeared in debug mode, you may be seeing a bug (https://github.com/Dart-Code/Dart-Code/issues/3477). This has recently been fixed but not released - although the fix is in the latest nightly build that you can install using the Extensions: Install from VSIX command in VS Code after downloading and extracting (see here for more details).

Get Dart Devtools to open in Chrome

Currently, Dart Devtools opens as a tab in VSCode. I want it to go back to opening in Chrome as it did in previous versions of Flutter.
Update VSCode to the newest Version.
VSCode Update
Update Flutter
flutter Update
Now run your Project and then click [ctrl] + [alt] + [d] for running dart devtools. VSCode is asking you where you wish to open DevTools.
Do not bother about it mate, just add this line on settings.json
"dart.embedDevTools": false
Then you will get again DevTools on Chrome. Just shortcode: Ctrl + Alt + D.
That's it.
In your terminal, run:
dart devtools
It will open Flutter Devtools page in your default browser. When you start an application is should print an id starting and ending with ws. This id will be used to connect devtools to the app
"dart.embedDevTools": false
is not relevant anymore, instead you should use:
"dart.devToolsLocation": "external"

Run Dart Console Application In Terminal with Visual Studio Code

I am trying to create a Dart console application that runs in the terminal rather than the Debug Console in Visual Studio Code.
Currently, when I press the play button:
It runs in the Debug Console. The problem with that is that the Debug Console cannot get user input from the line:
String userInput = stdin.readLineSync();
I know I can run the dart file from the terminal with:
dart C:\Applications\Dart\hello_world\bin\hello_world.dart
But I would prefer to use the play button out of convenience.
I found that you can edit the launch.json file to specify where it should run but it is not working. Even with the change shown in the picture below, it still runs in the debug console. In the picture you will notice a warning regarding how it only works with version from v2.7.1
I guess I was optimistic that the line "only supported for Dart SDKs from v2.7.1" was implying "SDKs from v2.7.1 and up.". However, it mostly likely means that version of the Dart SDK only.
Any help in achieving the goal of running a Dart file in the terminal using the Run button would be greatly appreciated.
If this is not possible, why would they take that functionality out of the newer Dart SDK's?
Your launch.json file is Ok, just check the file name. The main problem is that you use the debug button from the upper-right corner of the editor, but this button does not accept settings from launch.json.
You should use debug panel on the left side, as shown in the screenshot:
Make sure configuration's name (to the right of the green arrow) matches one from launch.json.

VSCode hot reload for flutter

I've just started playing with Flutter in VSCode. I also installed the Dart Plugin.
Running the demo app I read in the terminal
Is this the only way to hot-reload the app? I mean I should always keep the terminal open and focus on it to type "r" in order to reload my views?
Isn't there a shortcut directly from VSCode?
There's an extension for that. Called Dart Code and another one named Flutter Code
They will detect that your project is a Dart/Flutter project. And allows you to debug it + hot reload using f5.
For 2022, this solution worked.
Steps
Open Settings.
Paste this text > dart.flutterHotReloadOnSave on the settings search box.
And change value from "Manual" to "Always"
If you like to hot reload your app with a keybinding better than Ctrl+Shift+F5, just change the Debug: Restart to Ctrl+S, so whenever you trigger the the Ctrl+S the app will first save your changes according to the workbench.action.files.save and afterwards restart the app (=hot reload, it is the green circle you see in the debugbar).
Keybindings for VS Code:
VSCode debug -> start debuging, make a change and try, That's what you want.
No idea why F5 does not hot reload for me :(
But, you can map the -
Flutter: Hot Reload
command to whatever key combo floats your boat via -
Preferences > Keyboard ShortCuts
as in this screenshot -
open the Debug sidebar from VSCode and use it
then when you save, it will hot reload and apply the changes you make
that is what working with me
use the green reload button to hot reload the app in VS Code
on Mac select
Run without Debugging or Shift+f5
you will see this at top select the electric icon for Hot Reload.
After doing some changes save it. It will auto reflect changes.
yes Here is the plugin Dart Code for VS CODE
https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code
here is official doc for VsCode flutter
https://flutter.io/get-started/editor/#vscode
In VS once installed Dart + Flutter extension, 2 options to hot reload 1) Use combo keys Command + Shift + F5. 2) Save the file by use combo keys Command + S
I have both extensions and VSCode is set to Hot Reload once a document is saved. The only time I can reload my app is by stopping and restarting my debugger
i dont know why but my vscode hot reloading not work if you have this problem you can use ctrl + f5 to refresh app.
hope to work for developers that hot reloading not work for them.
You need to run Flutter app from VS Code's built-in debugger not VS Code's terminal.
Select ▷ then "Run without Debugging" -> You can now use ⌘S on Mac to ⚡ Hot Reload ⚡
===== Aug 2022 UPDATE =====
v3.42 and above: You can enable hot reload on autosave in the latest version by setting Flutter Hot Reload On Save to allIfDirty in your VSCode settings.
===== Old Versions (Early 2022 and below) =====
v3.41 and below: You can enable hot reload on autosave in the latest version by setting Flutter Hot Reload On Save to always in your VSCode settings.
v3.19 only: They disabled hot reload on autosave completely.
v3.18 and below: The extension hot reloads automatically when auto saving.
if flutter and dart extensions already installed on vscode
Set from manual to All
If you run your flutter project from the terminal you will have to manually press r to do a hot reload.
Therefore use the Run and Debug option in the VS Code to test your project.
You may encounter problems with Hot Reload due to VS Code issues like this, which is relevant while writing this answer.
The most convincing way I see to do it without downgrading, updating to Insiders builds and/or loosing dev speed is to use the green restart/reload button in the VS Code run widget or Ctrl+Shift+F5 shortcut, but this option may be inacceptable for projects with trickier navigation and few different views.