首页 > 解决方案 > 如果启动程序嵌套在内部深处,如何在 vscode 中调试颤振应用程序?

问题描述

简而言之有问题

我正在尝试使用 vscode 调试颤振应用程序,我收到以下警告,并且由于此问题末尾给出的错误,调试停止。显然它无法找到我的 dart sdk。但是我在设置中提供了sdk路径。

mobile_app/lib/main.dart:1: Warning: Interpreting this as package URI, 'package:mobile_app/main.dart'.

这篇中等帖子中提到了这个问题,但没有解决方案。您可能需要翻译该页面才能阅读它。


更多线索


我的文件夹结构

- 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'

标签: visual-studio-codeflutter

解决方案


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!).


推荐阅读