Pratik Satani
Pratik Satani

Reputation: 1205

How to solved 'dart:ui' error when going to run flutter app?

enter image description hereBelow error occurs when I try to run my first flutter app.

file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/action_sheet.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show ImageFilter;
       ^
 file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show ImageFilter;
       ^
file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/colors.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show Color;
       ^
file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/dialog.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show ImageFilter;
       ^
 file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/nav_bar.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show ImageFilter;
       ^
 file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/slider.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
 file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/cupertino/switch.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
 file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
       ^   file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^  file:///Volumes/Data/FlutterSDk/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^

Process finished with exit code 254

I have tried many ways to solve this issue but still, this issue is coming.

Upvotes: 20

Views: 68537

Answers (14)

Jacob
Jacob

Reputation: 1

I encountered the same issue, and it was caused by forgetting to uncomment the assets section in the pubspec.yaml file after adding an image. This led to the dart:ui error when running my Flutter app.

Here’s how I solved it:

Open the pubspec.yaml file. Locate the flutter: section. Uncomment the assets section and ensure your assets are correctly listed under it. For example:

flutter: assets: - assets/images/your_image.png

Save the file and run:

Rebuild your app.

After fixing this, the error was resolved. The dart:ui error often appears if Flutter cannot find required assets, so ensuring your pubspec.yaml file is correctly configured is crucial.

Upvotes: 0

J Michael
J Michael

Reputation: 109

Having recently experienced this swapping main.dart files in Android Studio (Ladybug), I gratefully concur with ketan-ramteke and salihgueler . The only difference for me was that there was no Flutter-iconed main.dart. So, I created it, entering 'Edit Configurations...', and under Flutter, clicking the '+', completing the Name and Data entrypoint fields with name of location of the newly-minted main.dart, clicking Apply and OK. Then my new main.dart properly appeared, Flutter-iconized, from the configurations menu to be run as Flutter, in lieu of the Dart config it had been. No more errors.

Android Studio Run/Debug Configurations Menu

Upvotes: 0

parten
parten

Reputation: 1

Got this error in IntelliJ after upgrading to the new version 2024.1. I found out it was android plugin that failed to load so flutter plugin also failed because it depends on that. In the plugins section, make sure the andoid and the flutter plugins are working correctly. My android plugin was showing dependency error so i upgraded it, restarted the IDE and everything came back to normal. May help for anyone doing flutter dev using IntelliJ IDE.

Upvotes: 0

Gagandeep Bajaj
Gagandeep Bajaj

Reputation: 1

I encountered the same error. I resolved it in VSCode by running the flutter run command in the VSCode terminal. When I just pressed Run, it was running as a Dart file, but with flutter run it worked as Flutter file.

Upvotes: 0

Ali Erdem Toraman
Ali Erdem Toraman

Reputation: 11

This may be incredibly basic and seem like a ridiculous suggestion, but make sure that you have void main() {} inside your main.dart file.

Upvotes: 0

Sam T
Sam T

Reputation: 1

In my case, assets: was not correctly placed in the pubspec.yaml, make sure to follow the field convention correctly because VScode does not format that file

Upvotes: 0

You just have to debug the program, if you're usign vscode, press control/command + shift + p and debug the project, afetr that is solved

Upvotes: 0

Metmiku Yohannes
Metmiku Yohannes

Reputation: 1

If you're on VS code and are using extensions to run the code, don't. You should disable them and use the flutter extension it self to launch the main.dart.

Upvotes: 0

Ketan Ramteke
Ketan Ramteke

Reputation: 10675

You are getting those errors because your IDE is executing main.dart as a simple dart application and not as a Flutter application.

As answered by salihguler, if you are using Android SDK then choose the main.dart file with Flutter Icon beside it and not the one with Dart Icon and the project should work just fine.

Android SDK Option Image

If you are using VS Code then instead of hitting Run (Ctrl+Alt+N) go to Debug -> Start Debugging option or simply press F5 and errors will be gone.

Visual Code Option Image

Upvotes: 46

RobDil
RobDil

Reputation: 4544

For me the culprit was a transitive dependency on Flutter. I was running a dart file that imported a functional class that I copied from another project. This class did not apparently depend on Flutter but it was importing a package for logging and that package was depending on Flutter.

When running a dart executable, make sure you do not use any Flutter specific classes anywhere.

Upvotes: 2

Jay Dangar
Jay Dangar

Reputation: 3479

I was having the same problem, but pressing "F5 running on debug mode" worked for me. Additionally I don't need to install XCode and Android Studio as well, which was described as a problem in flutter doctor command.

Upvotes: 0

Aelaf
Aelaf

Reputation: 118

had the same error message when working on command line based dart files, i had accidentally

imported cupertino packages on some dart files. try using material design only on your project and remove the cupertino package import on your files P.S i had no issue working on the real flutter app. and i use android studio

Upvotes: 0

salihgueler
salihgueler

Reputation: 3632

When you run the app, you will see 2 main.dart entry. Please pick the one with Flutter icon. I get it from here.

enter image description here

Upvotes: 30

Tokenyet
Tokenyet

Reputation: 4291

If you are using VSCode, you might need to open Folder more closely to your main.dart.

Bad Folder Structure Example on the left side:

  • Backend
  • Frontend
    • FlutterApp
    • lib
      • main.dart

Working:

  • FlutterApp
    • lib
      • main.dart

Finally, I saved workplace as second one, and changed to first one, all works! Here is the related issue discussion.

Upvotes: 0

Related Questions