Dart-Code: Error: Not found: 'dart:ui' when trying to run a Flutter project

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)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 27 (13 by maintainers)

Most upvoted comments

@Chetan34123456 the two most common cases of this are:

  1. Project is not detected as a Flutter project. You can tell if this is the case because it was show a Dart SDK version (“Dart x.y.z”) in the status bar, or the words “Dart from Flutter”. If it shows “Flutter x.y.z” in the status bar, then this is not the problem. If this is the problem, it’s usually caused by not opening the Flutter projects folder correctly, or not having Flutter correctly referenced in the pubspec.yaml.
  2. Clicking the Run buttons contributed by the Code Runner extension. Code Runner does not understand Flutter projects and tries to run everything with Dart. If this is the problem you should just launch the app using F5 or the “other” run button, or the Run menu.

If it’s neither of these, please run the Dart: Capture Debugging Logs command from the command palette (F1), try to run the app (to generate the error), then click Cancel on the logging notification to stop logging and open the log file, then file a new issue with the log attached.

Note: The log will contain parts of your source, so best to repro in a clean project (created with the Flutter: New Project command).

if you have the code runner extension installed, you may end up with that extension and not the flutter one.

Done! This will be included in the next release, thanks!

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.

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.

/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

@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 `

@clebemachado You can’t use dart:ui in Dart projects, as it’s part of Flutter - see https://github.com/dart-lang/sdk/issues/50854#issuecomment-1366596944.

Releases are usually monthly (and usually in the first week of the month). There are often pre-release versions in the last week or so of a month too (see https://dartcode.org/releases/v3-32/#v3320-2022-01-02).

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

https://github.com/Dart-Code/Dart-Code/blob/2f9483a71327ca010434a985b109bea7f99e8985/src/extension/providers/debug_config_provider.ts#L315

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

https://github.com/Dart-Code/Dart-Code/blob/2f9483a71327ca010434a985b109bea7f99e8985/src/extension/sdk/utils.ts#L430-L436