Skip to content

Error: Not found: 'dart:ui' when trying to run a Flutter project #3834

Closed

Description

@noordawod

Trying to run a Flutter project in VS Code yields many errors like this: Error: Not found: 'dart:ui'.

From looking at other issues (#2038, #1827) I understand that this is caused by trying to run a Dart project rather than a Flutter project. Well, I believe this is not the case in my project since the status bar does show Flutter and its version, in addition to selection of an emulator. The doctor also reports no issues whatsoever.

To Reproduce

I cannot share my code with the community (closed source), but the project opens and runs fine in both Android Studio and IntelliJ IDEA. The top-level directory contains a pubspec.yaml with a line reading sdk: "flutter".

Expected behavior
The project runs as a Flutter project.

Screenshots

Screenshot_2022-02-17_08-52-14

Screenshot_2022-02-17_08-53-30

Screenshot_2022-02-17_09-02-17

Versions (please complete the following information):

  • VS Code version: 1.64.2
  • Dart extension version: 3.34.0
  • Dart/Flutter SDK version: Flutter 2.11.0-0.0.pre.582 • channel master • Dart 2.17.0 (build 2.17.0-105.0.dev)

Activity

  1. DanTup commented on Feb 17, 2022

    @DanTup
    Member

    Are you able to make a small project in the same structure that triggers this that you can share?

    Could you try capturing debugging logs while reproducing this?

    • Run the Dart: Capture Debugging Logs command
    • Reproduce the issue
    • Click Cancel on the logging notification to stop logging and open the log
    • Remove anything sensitive from the log
    • Attach the log here (or in a gist)

    Thanks!

  2. added
    awaiting infoRequires more information from the customer to progress
    on Feb 17, 2022
  3. noordawod commented on Feb 17, 2022

    @noordawod
    Author

    From the log: [9:12:04 AM] [General] [Info] Project (/path/to/workspace/app/lib/googledevel.dart) not recognised as Flutter or Web, will use Dart debugger. I don't get why it's not being detected as Flutter, when 5 other subdirectories alongside it (admin, core, ui, ui_mobile, db) are detected as Flutter projects.

    The structure of the workspace:

    /path/to/workspace
    |__ project.code-workspace
    |__ admin/
    |     |__ pubspec.yaml
    |     |__ lib/
    |__ app/
    |     |__ pubspec.yaml
    |     |__ lib/
    |__ core/
    |     |__ pubspec.yaml
    |     |__ lib/
    |__ db/
    |     |__ pubspec.yaml
    |     |__ lib/
    |__ ui/
    |     |__ pubspec.yaml
    |     |__ lib/
    |__ ui_mobile/
          |__ pubspec.yaml
          |__ lib/
    

    All of them are Flutter projects. Only the app/ subdirectory is not detected as a Flutter project... I'm baffled.

  4. noordawod commented on Feb 17, 2022

    @noordawod
    Author

    .vscode/launch.json looks like so:

    {
      "configurations": [
        {
          "name": "App (Devel)",
          "type": "dart",
          "request": "launch",
          "cwd": "app/",
          "program": "lib/googledevel.dart",
          "args": [
            "--no-sound-null-safety",
            "--enable-experiment=non-nullable",
            "--enable-experiment=nonfunction-type-aliases",
            "--enable-experiment=constructor-tearoffs"
          ]
        }
      ]
    }
  5. DanTup commented on Feb 17, 2022

    @DanTup
    Member

    [9:12:04 AM] [General] [Info] Project (/path/to/workspace/app/lib/googledevel.dart) not recognised as Flutter or Web, will use Dart debugger

    Are you able to share the log (here or emailing me at [email protected])? The path there is supposed to be a project folder, so having lib/googledevel.dart on the end looks odd. Could you also share the pubspec.yaml for the app project?

  6. DanTup commented on Feb 17, 2022

    @DanTup
    Member

    Sorry, I was mistaken - we log the program not the project folder. But we use the debugConfig.cwd to check for Flutter:

    if (isFlutterProjectFolder(debugConfig.cwd) || this.wsContext.config.forceFlutterDebug) {

    The detection of the SDK is a regex, so if your formatting is different here, perhaps that would do it:

    export function referencesFlutterSdk(folder?: string): boolean {
    if (folder && hasPubspec(folder)) {
    const regex = new RegExp("sdk\\s*:\\s*flutter", "i");
    return regex.test(fs.readFileSync(path.join(folder, "pubspec.yaml")).toString());
    }
    return false;
    }

  7. noordawod commented on Feb 17, 2022

    @noordawod
    Author

    [9:12:04 AM] [General] [Info] Project (/path/to/workspace/app/lib/googledevel.dart) not recognised as Flutter or Web, will use Dart debugger

    Are you able to share the log (here or emailing me at [email protected])? The path there is supposed to be a project folder, so having lib/googledevel.dart on the end looks odd. Could you also share the pubspec.yaml for the app project?

    Basically, I specify a different template file to run (flutter run -t ...) and that's what you saw there, the lib/googledevel.dart). I referred to it earlier as lib/devel.dart mistakenly.

    Anyway, I sent you the log to: [email protected].

  8. noordawod commented on Feb 17, 2022

    @noordawod
    Author

    app/pubspec.yaml (strippe down) is below:

    name: "flutter_app"
    publish_to: "none"
    version: "1.0.0"
    
    environment:
      sdk: ">=2.16.0 <3.0.0"
      flutter: ">=2.10.0"
    
    dependencies:
      # List of all deps comes here...
    
      flutter:
        sdk: "flutter"
    
      flutter_localizations:
        sdk: "flutter"
    
    dev_dependencies:
      analyzer: "3.2.0"
      build_runner: "2.1.7"
      flutter_lints: "1.0.4"
    
    flutter:
      generate: true
      uses-material-design: false
      assets:
        - "res/"
  9. DanTup commented on Feb 17, 2022

    @DanTup
    Member

    Thanks! At a glance, I think it's because of the quotes in sdk: "flutter". I'll improve the regex to handle these better, but if you can remove them in the meantime it should solve your issue.

  10. added
    in flutterRelates to running Flutter apps
    and removed
    awaiting infoRequires more information from the customer to progress
    on Feb 17, 2022
  11. added this to the v3.36.0 milestone on Feb 17, 2022
  12. changed the title [-]Error: Not found: 'dart:ui'[/-] [+]Error: Not found: 'dart:ui' when trying to run a Flutter project[/+] on Feb 17, 2022
  13. noordawod commented on Feb 17, 2022

    @noordawod
    Author

    Thanks! At a glance, I think it's because of the quotes in sdk: "flutter". I'll improve the regex to handle these better, but if you can remove them in the meantime it should solve your issue.

    Trying... Yup, this seems to have fixed the problem.

    It's great that you uncovered the reason! You should probably check for single- and double-quotes as well.

  14. 11 remaining items

  15. DanTup commented on May 27, 2023

    @DanTup
    Member

    @clebemachado You can't use dart:ui in Dart projects, as it's part of Flutter - see dart-lang/sdk#50854 (comment).

  16. deemKhlaed commented on Aug 2, 2023

    @deemKhlaed

    @DanTup hi , I still have the same problem
    could you plz help me
    `
    name: projectName
    description: A new Flutter project.

    publish_to: 'none'

    version: 1.0.0+1

    environment:
    sdk: '>=3.0.6 <4.0.0'

    dependencies:
    flutter:
    sdk: flutter
    cupertino_icons: ^1.0.2

    dev_dependencies:
    flutter_test:
    sdk: flutter

    flutter_lints: ^2.0.0

    flutter:

    uses-material-design: true
    `

  17. DanTup commented on Aug 2, 2023

    @DanTup
    Member

    @deemKhlaed please file a new issue and include a screenshot of exactly what you're seeing, and details of how you are running the application. Thanks!

  18. nitinyeranale commented on Oct 19, 2023

    @nitinyeranale

    /C:/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Dart library 'dart:ui' is not available on this platform.
    import 'dart:ui' show lerpDouble;

    Please suggest the answer

  19. DanTup commented on Oct 19, 2023

    @DanTup
    Member

    @nitinyeranale please file a new issue and include a full VS Code screenshot of exactly what you're seeing, and details of how you are running the application. Thanks!

  20. YusufBabali commented on Feb 9, 2024

    @YusufBabali

    Ekran görüntüsü 2024-02-09 223830

    Hi Mr.
    I add my problem as a ss.
    when I run my code by the f5 button problem it works but i couldn't run it from the terminal as seen on SS by writing " dart lib/main.dart "
    It's not a problem for now but I feel it going to in further steps.

  21. DanTup commented on Feb 9, 2024

    @DanTup
    Member

    but i couldn't run it from the terminal as seen on SS by writing " dart lib/main.dart "

    This is expected behaviour. Flutter apps are run with flutter run not dart. Only Dart (non-Flutter) apps can be run with dart.

    I would recommend using F5/Ctrl+F5 in VS Code though, as you'll get more functionality (such as the debugger) compared to running from the terminal.

  22. YusufBabali commented on Feb 9, 2024

    @YusufBabali

    Thank you Mr @DanTup . Your response speed is incredible.

  23. bth-ik commented on May 21, 2024

    @bth-ik

    Basically i have issues but i think my problem is my friend give code source which has old version of dart and flutter than i have on my pc so that's cause problem in pubspec.yaml but when i do any change in yaml folder ,the code won't execute like i don't which line attributes that i should change (sorry for my bad english)

  24. DanTup commented on May 21, 2024

    @DanTup
    Member

    @Boutheinaikram I don't think an old version of Dart/Flutter should cause this error, but please open a new issue with a screenshot showing all of VS Code and any error messages so I can take a look. Thanks!

  25. bth-ik commented on May 21, 2024

    @bth-ik

    Screenshot 2024-05-21 174941
    Screenshot 2024-05-21 175016
    Screenshot 2024-05-21 175456

    Screenshot 2024-05-21 175550
    Screenshot 2024-05-21 175614

    @Boutheinaikram I don't think an old version of Dart/Flutter should cause this error, but please open a new issue with a screenshot showing all of VS Code and any error messages so I can take a look. Thanks!

    here's all the screenshot of all errors and output thanks in advance

  26. DanTup commented on May 22, 2024

    @DanTup
    Member

    @Boutheinaikram based on the screenshot, I think you may be running using the Code Runner extension? See my comment above at #3834 (comment)

    The Code Runner extension does not understand Flutter and will try to run Flutter apps using dart instead of flutter. I would recommend disabling the Code Runner extension in any Dart/Flutter workspaces and using the options from the Dart/Flutter extensions instead.

    There's an issue at formulahendry/vscode-code-runner#674 asking for Code Runner to hides it buttons for Dart/Flutter but it unfortunately has not received any response.

  27. bth-ik commented on May 22, 2024

    @bth-ik

    i try all ur step but the problem is same and actualy i use android studio to execute ,my friend coded the app in an older version of Dart (3.3.0), and it worked perfectly. However her pc broke, so she transferred her app to my pc. I installed the latest version of dart (3.4.0) and flutter (3.2.0). When I tried to execute it in Android Studio, it didn't work because there was a problem with dart:ui. I thought the issue might be due to the code not being compatible with the versions I have on my pc. So
    I tried to modify the pubspec.yaml file because it had sdk: '>=2.19.6 <3.0.0'. I changed it to sdk: '>=3.0.6 <4.0.0', but it still didn't work. I made sure that the path is correct and everything is clear, but I still don't know where the problem is. here's the error in android studio

    Screenshot 2024-05-22 190407

  28. DanTup commented on May 22, 2024

    @DanTup
    Member

    @Boutheinaikram the error in your latest screenshot is a different error.

    The error shown in your earlier post from VS Code looks like a problem caused by using Code Runner (or something else that's using dart to run a Flutter app).

    The error in your latest screenshot is indeed because of version changes - the code is trying to use ThemeData.backgroundColor but that was deprecated in Flutter 3.3 and removed in Flutter 3.19. You will need to update the code to make it compatible with the latest versions of Flutter or switch back to an older Flutter SDK. You might be able to use dart fix to update some of these (see https://docs.flutter.dev/tools/flutter-fix).

    There are a number of places listed at https://flutter.dev/community#community-grid that may be better suited for general Flutter coding questions/help.

  29. added a commit that references this issue on Sep 2, 2025
    4486b82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions