有没有办法在模拟器中检查Flutter应用程序元素? 我正在使用VS Code而不是Android Studio,我想从运行的模拟器中检查元素。
有没有办法在模拟器中检查Flutter应用程序元素? 我正在使用VS Code而不是Android Studio,我想从运行的模拟器中检查元素。
在Flutter项目中检查Widget:
1- 打开命令面板(Ctrl+Shift+P(macOS上为Cmd+Shift+P))。
2- 选择Flutter:检查Widget命令并按Enter键。
3- 在模拟器中点击任意widget。
4- 查看widget树形结构。
5- 祝你好运。
我使用快捷键:Ctrl+Alt+D(在 Ubuntu + VSCode 中)。
不要忘记应用程序必须已经在调试模式下运行,就像 Evandro 提到的那样。
实际上,当你在运行 flutter run
后在终端中输入 h
,你会得到所有这些内容;
Flutter run key commands.
r Hot reload.
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
s Save a screenshot to flutter.png.
b Toggle the platform brightness setting (dark and light mode). (debugBrightnessOverride)
w Dump widget hierarchy to the console. (debugDumpApp)
t Dump rendering tree to the console. (debugDumpRenderTree)
L Dump layer tree to the console. (debugDumpLayerTree)
S Dump accessibility tree in traversal order. (debugDumpSemantics)
U Dump accessibility tree in inverse hit test order. (debugDumpSemantics)
i Toggle widget inspector. (WidgetsApp.showWidgetInspectorOverride)
I Toggle oversized image inversion ️. (debugInvertOversizedImages)
p Toggle the display of construction lines. (debugPaintSizeEnabled)
o Simulate different operating systems. (defaultTargetPlatform)
z Toggle elevation checker.
g Run source code generators.
M Write SkSL shaders to a unique file in the project directory.
v Launch DevTools.
P Toggle performance overlay. (WidgetsApp.showPerformanceOverlay)
a Toggle timeline events for all widget build methods. (debugProfileWidgetBuilds)
v
。更新的方法:
Android Studio有一个Flutter Inspector,VS Code也有类似的称为Widget Inspector。
截至Dart Code(VS Code扩展)版本2.24.0,“Flutter: Inspect Widget”命令已被DevTools替换。(在撰写本文时,最新版为3.36.0。要从命令面板中访问Inspect Widget,需执行多个步骤。)
在使用模拟器时快速打开Widget Inspector的方式是以调试模式运行Flutter应用程序。
Click the debug (bug) button from the side menu and Select Run and Debug or press f5