visual-studio-code - 如果启动程序嵌套在内部深处,如何在 vscode 中调试颤振应用程序?
问题描述
简而言之有问题
我正在尝试使用 vscode 调试颤振应用程序,我收到以下警告,并且由于此问题末尾给出的错误,调试停止。显然它无法找到我的 dart sdk。但是我在设置中提供了sdk路径。
mobile_app/lib/main.dart:1: Warning: Interpreting this as package URI, 'package:mobile_app/main.dart'.
这篇中等帖子中提到了这个问题,但没有解决方案。您可能需要翻译该页面才能阅读它。
更多线索
- 仅当我的主程序嵌套深度超过两层时才会发生这种情况。我有一个深度嵌套的文件夹结构(如下所示)。
main.dart
文件在foo/code/ui/mobile_app/lib
并且.vscode/launch.json
在foo
. 我已经launch.json
为 vscode 提供了这个路径。如果我将其.vscode/launch.json
放入并在 vscode中ui
打开文件夹或将其放在.ui
mobile_app
- 这只发生在 vscode 中。(我尝试的另一个 IDE 是 Android Studio)
我的文件夹结构
- foo
- .vscode
# launch.json
- code
+ domain (this is a dart lib (shared code))
- ui
- mobile_app
- lib
# main.dart
+ web_app
+ design
启动.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Jamsalon Mobile App",
"program": "code/ui/mobile_app/lib/main.dart",
"request": "launch",
"type": "dart"
}
]
}
完全错误
mobile_app/lib/main.dart:1: Warning: Interpreting this as package URI, 'package:mobile_app/main.dart'.
file:///C:/Users/random_user/Documents/app_development/frameworks/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
^
file:///C:/Users/random_user/Documents/app_development/frameworks/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
^
file:///C:/Users/random_user/Documents/app_development/frameworks/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
^
file:///C:/Users/random_user/Documents/app_development/frameworks/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
^
file:///C:/Users/random_user/Documents/app_development/frameworks/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
^
file:///C:/Users/random_user/Documents/app_development/frameworks/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
解决方案
These errors are because your project is not being detected as a Flutter project (because of the deep nesting). When a Dart project is open, the plugin has to decide whether to go into "Flutter mode" and look for a Flutter SDK (and invoke flutter
commands) or "Dart mode" (looking for a standard Dart SDK and using dart
and pub
commands).
For performance reasons, it only scans the top two levels of folders when making this decision. If you have a Flutter project nested many levels deep, it will go into "Dart mode".
My recommendation would be to use the multi-root workspace feature of VS Code so that the Flutter project is available further up (or as a workspace folder). For example, if you click File -> Add Folder to Workspace and then browser to your mobile_app
folder, that should fix it. Unfortunately this experience isn't as nice as I wish it was (you'll now see mobile_app
duplicated at the top-level of your Explorer tree) because of https://github.com/Microsoft/vscode/issues/45470 (please add a to that!).
推荐阅读
- java - How to perform stream and map in List of String Arrays in Java?
- r - 如何强制闪亮更新来自不同 Flex Dashboard 部分的所有反应元素?
- .net-core - 如何查找 .Net core 3.1 应用程序中使用的 Microsoft.AspNetCore.App 版本
- java - 应用程序构建成功但出现错误:运行图像时出现“没有主清单属性,在 app.jar 中”
- postgresql - 按字母顺序排列具有逗号分隔值的字段
- python - 在anaconda中创建python环境时出错
- kubernetes - 它如何为 pod 中的容器创建关闭序列?
- javascript - Redux Saga - 生成器不应该产生吗?
- javascript - 具有默认值的打字稿固定数组
- android - 使用 Lambda 更新可组合函数