You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error: Not found: 'dart:ui' when trying to run a Flutter project #3834
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
Versions (please complete the following information):
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.
[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?
[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.
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.
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.
@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!
/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;
@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!
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.
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)
@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!
@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
@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.
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
@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).
Activity
DanTup commentedon Feb 17, 2022
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?
Thanks!
noordawod commentedon Feb 17, 2022
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:
All of them are Flutter projects. Only the
app/subdirectory is not detected as a Flutter project... I'm baffled.noordawod commentedon Feb 17, 2022
.vscode/launch.jsonlooks 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" ] } ] }DanTup commentedon Feb 17, 2022
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.darton the end looks odd. Could you also share thepubspec.yamlfor theappproject?DanTup commentedon Feb 17, 2022
Sorry, I was mistaken - we log the
programnot the project folder. But we use thedebugConfig.cwdto check for Flutter:Dart-Code/src/extension/providers/debug_config_provider.ts
Line 315 in 2f9483a
The detection of the SDK is a regex, so if your formatting is different here, perhaps that would do it:
Dart-Code/src/extension/sdk/utils.ts
Lines 430 to 436 in 2f9483a
noordawod commentedon Feb 17, 2022
Basically, I specify a different template file to run (
flutter run -t ...) and that's what you saw there, thelib/googledevel.dart). I referred to it earlier aslib/devel.dartmistakenly.Anyway, I sent you the log to: [email protected].
noordawod commentedon Feb 17, 2022
app/pubspec.yaml(strippe down) is below:DanTup commentedon Feb 17, 2022
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.[-]Error: Not found: 'dart:ui'[/-][+]Error: Not found: 'dart:ui' when trying to run a Flutter project[/+]noordawod commentedon Feb 17, 2022
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.
11 remaining items
DanTup commentedon May 27, 2023
@clebemachado You can't use
dart:uiin Dart projects, as it's part of Flutter - see dart-lang/sdk#50854 (comment).deemKhlaed commentedon Aug 2, 2023
@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
`
DanTup commentedon Aug 2, 2023
@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!
nitinyeranale commentedon Oct 19, 2023
/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 commentedon Oct 19, 2023
@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!
YusufBabali commentedon Feb 9, 2024
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.
DanTup commentedon Feb 9, 2024
This is expected behaviour. Flutter apps are run with
flutter runnotdart. Only Dart (non-Flutter) apps can be run withdart.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.
YusufBabali commentedon Feb 9, 2024
Thank you Mr @DanTup . Your response speed is incredible.
bth-ik commentedon May 21, 2024
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)
DanTup commentedon May 21, 2024
@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!
bth-ik commentedon May 21, 2024
here's all the screenshot of all errors and output thanks in advance
DanTup commentedon May 22, 2024
@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
dartinstead offlutter. 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.
bth-ik commentedon May 22, 2024
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
DanTup commentedon May 22, 2024
@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
dartto run a Flutter app).The error in your latest screenshot is indeed because of version changes - the code is trying to use
ThemeData.backgroundColorbut 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 usedart fixto 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.
Make detection of Flutter projects tolerate quotes in pubspec