12

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Pratik Satani
  • 1,115
  • 1
  • 9
  • 25

8 Answers8

38

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

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ketan Ramteke
  • 10,183
  • 2
  • 21
  • 41
23

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

Aleksandr Belugin
  • 2,149
  • 1
  • 13
  • 19
salihgueler
  • 3,284
  • 2
  • 22
  • 33
2

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.

RobDil
  • 4,036
  • 43
  • 52
0

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.

Tokenyet
  • 4,063
  • 2
  • 27
  • 43
0

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

Aelaf
  • 118
  • 1
  • 11
0

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.

Jay Dangar
  • 3,271
  • 1
  • 16
  • 35
0

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
0

dude this is a bit silly and ridiculous but are you sure you have the code void main(){} inside your main.dart file?