61

When I start a debugging session (pressing F5) I receive the following messages:

dart:ui:1: Error: Not found: dart:ui.
Exited (sigterm)

There is no indication as to where the problem occurred. Output from flutter doctor -v is:

[√] Flutter (Channel beta, v0.8.2, on Microsoft Windows [Version 6.1.7601], locale en-US)
    • Flutter version 0.8.2 at C:\Downloads\flutter\flutter_windows_v0.5.1-beta\flutter
    • Framework revision 5ab9e70727 (2 weeks ago), 2018-09-07 12:33:05 -0700
    • Engine revision 58a1894a1c
    • Dart version 2.1.0-dev.3.1.flutter-760a9690c2

[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at C:\Users\gggustafson\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    • All Android licenses accepted.

[√] Android Studio (version 3.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[√] VS Code, 64-bit edition (version 1.25.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 2.18.0

[√] Connected devices (1 available)
    • SM G925V • 06157df60c7a8e20 • android-arm64 • Android 7.0 (API 24)

• No issues found!

Any thoughts?

Gus
  • 1,383
  • 2
  • 12
  • 23
  • 2
    It seems your IDE infer your application as a simple dart project, not a flutter one. – Rémi Rousselet Sep 24 '18 at 16:37
  • 1
    What file are you using as entry-point? You see it if you click the configuration dropdown on the left side of the run button in the toolbar and click `Edit Configurations ...` – Günter Zöchbauer Sep 24 '18 at 16:46
  • 1
    In the Debug, next to the Start Debugging icon, there is a drop-down from which can be selected either "No Configurations" or "Add Configuration...". Currently the selected configuration is "No Configurations". – Gus Sep 24 '18 at 17:24
  • Sorry, missed the first part of your question. I am working on a conversion of the Vanilla project from GitHub. I am trying to: combine all dart files into a minimum number of directories, then remove all "unnecessary" files (localization, etc.) and reduce Vanilla to an example of application state sharing, and finally using the revised Vanilla as an example, write my own app. The entry point is main() in main.dart. Have I answered your question? – Gus Sep 24 '18 at 19:19
  • Did you enable Flutter support for the project. Check that the Dart SDK from Flutter is selected in Dart settings instead of a standalone Dart SDK – Günter Zöchbauer Sep 27 '18 at 18:55
  • In the Dart Configuration setting, I find In the default settings: "dart.checkForSdkUpdates": true, "dart.debugSdkLibraries": false, "dart.flutterSdkPath": "", "dart.flutterSdkPaths": [], "dart.sdkPath": "", "dart.sdkPaths": [], In the user settings: "dart.sdkPath": "", Thoughts? – Gus Sep 27 '18 at 19:41
  • In my case, Android Studio identfied all but one of my test classes as Flutter tests. In order to correct it, I had to 'edit configuration', DELETE the incorrectly associated test and enter it again as a Flutter test. Editing the existing entry did not work. – Curt Eckhart Jun 19 '19 at 23:48
  • maybe your FlutterSDK is not defines, see this: https://stackoverflow.com/questions/48650831/dart-sdk-is-not-configured – SamPhoenix Mar 01 '20 at 16:52

7 Answers7

146

When running the app, you will find 2 main.dart Choose the one with the flutter icon beside it enter image description here

Sunny
  • 3,134
  • 1
  • 17
  • 31
Mohammed Hassan
  • 1,589
  • 1
  • 8
  • 6
  • 1
    Thank you for your thoughts. The problem has disappeared. I don't know why but I did flutter new project. I think that was the problem. – Gus Oct 15 '18 at 20:18
15

If you are running flutter project.

In edit configuration, run it as flutter project,which has a flutter icon besides it.

If you are testing a dart file

Check your denpendency tree. Delete all flutter related lib like widgets/material/cupertino.

Simple explaination

In short, you are running a file as dart file, but you have imported flutter dependencies like widgets/material at the same time. Either run it as flutter ,or get rid of flutter dependency and run pure dart.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Zony Zhao
  • 559
  • 5
  • 10
13

If you are using VS Code as your IDE then choose Start Debugging instead of Run Code and it will work.

Screenshot here

Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94
raiyan22
  • 1,043
  • 10
  • 20
7

Magically if you add:

import 'package:flutter/widgets.dart';

at the top of that file you want to Run or Debug, and delete the existing configuration, it will run as flutter instead of dart.

Why? Idea/Android Studio scans the file that you're asking to Run or Debug for flutter imports and uses that to decide whether the initial run configuration should be a dart or flutter one. If you import any flutter packages, you get a flutter run configuration.

Confusingly, it does this only the first time you Run/Debug that file, and remembers the run configuration. If your run configuration was created as the wrong kind (Dart instead of Flutter), you'll need to go into the "Edit Configurations" menu to delete it, than are to Run/Debug that file again.

Its very confusing behavior, particularly since your imports are insufficient to know whether the file should be run as Flutter or plain old Dart -- your file's import may import another file that imports a flutter library. It may be detected as Dart, when Flutter it the right configuration.

They should have just added "Run Dart", "Run Flutter".

user48956
  • 14,850
  • 19
  • 93
  • 154
  • hm? where file do you mean? – shinriyo May 05 '20 at 01:06
  • 1
    At the top of the file that you are trying to run or debug. Idea/Android Studio scans the for for flutter imports and uses that to decide whether the initial run configuration should be a dart or flutter one. If you import any flutter packages, you get a flutter run configuration. – user48956 May 05 '20 at 01:09
1

While running choose the one with the flutter icon and it should help.

Bilol
  • 36
  • 3
1

Has the same problem for almost a week. My solution was to debug (Start Debug) and not Run (Run Code).

Kevin Owino
  • 472
  • 3
  • 7
-5

import this liberary import 'dart:ui' as ui;