'dart:ui:1: Error: Not found: dart:ui. flutter/dart:

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?



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sunny
Solution 2 CopsOnRoad
Solution 3
Solution 4 Walied Abdulaziem