32
votes

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?

5
It seems your IDE infer your application as a simple dart project, not a flutter one.Rémi Rousselet
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
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
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
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 SDKGünter Zöchbauer

5 Answers

99
votes

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

5
votes

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.

3
votes

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".

0
votes

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

-4
votes

The following helped me:

  1. flutter channel. Make sure you're on master. If not: flutter channel master
  2. flutter upgrade said I had untracked changes. Probably after I had been jumping between channels.
  3. flutter upgrade --force fixed the issue though the version (flutter --version) remained the same.

Seems like some local inconsistency in flutter directory after switching channels.

FYI. I was playing with Flutter for desktop so after enabling the feature and switching to master I started to see the new device after flutter devices:

SM G973F • RF8M206V4LW • android-arm64 • Android 9 (API 28)
Windows  • Windows     • windows-x64   • Microsoft Windows [Version 10.0.17134.1130]

If it's your case, when running your app with flutter run make sure to add -d RF8M206V4LW or -d Windows to run against the correct device.