-1

I've cloned a certain repository from Github to my VSCode Editor but this is the output every time I try running the code.

[Running] dart "/home/linusanari_/Documents/Flutterprojects/hopOn/lib/main.dart" lib/main.dart: Warning: Interpreting this as package URI, 'package:vehicle_sharing_app/main.dart'. ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/action_sheet.dart:5:8: Error: Not found: 'dart:ui' import 'dart:ui' show ImageFilter; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart:5:8: Error: Not found: 'dart:ui' import 'dart:ui' show ImageFilter; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/colors.dart:5:8: Error: Not found: 'dart:ui' import 'dart:ui' show Color, Brightness; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/context_menu.dart:6:8: Error: Not found: 'dart:ui' import 'dart:ui' as ui; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/dialog.dart:6:8: Error: Not found: 'dart:ui' import 'dart:ui' show ImageFilter; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/nav_bar.dart:6:8: Error: Not found: 'dart:ui' import 'dart:ui' show ImageFilter; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/route.dart:6:8: Error: Not found: 'dart:ui' import 'dart:ui' show lerpDouble, ImageFilter; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/slider.dart:6:8: Error: Not found: 'dart:ui' import 'dart:ui' show lerpDouble; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/switch.dart:5:8: Error: Not found: 'dart:ui' import 'dart:ui' show lerpDouble; ^ ../../../snap/flutter/common/flutter/packages/flutter/lib/src/cupertino/text_field.dart:5:8: Error: Not found: 'dart:ui' import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; ^

[Done] exited with code=254 in 15.987 seconds

Any insight/help will be much appreciated.

3
  • 1
    Try typing at your terminal flutter clean && flutter pub get and rebuild to see if it is solved. Commented Sep 5, 2021 at 14:46
  • This error often arises when you try to do a flutter run with any other extension like Code Runner etc. You'll explicitly need to define the configuration. P.S if you notice the error stack never contains the main.dart in the logs and this is due to no configuration set hence your app is automatically built from some random file selected by the extension. Commented Sep 5, 2021 at 21:49
  • So how do I go around it? Commented Sep 6, 2021 at 22:16

4 Answers 4

3

To run an Flutter project in VS Code use menu "Execute > Start Debugging (F5)" or menu "Execute > Start Without Debugging (Ctrl+F5)".

Do NOT use "Run Code" button (triangle icon on upper right corner of edit window), because VS Code will try to run only that file, and not the whole project, what generates error messages like "Error: Not found: 'dart:ui'".

Sign up to request clarification or add additional context in comments.

Comments

2

There are some bugs in VSCode about library getting. You should try several time these flow until error fixed.

flutter clean 
flutter pub get

1 Comment

this doesn't help
1

Solution: I got that error when I loaded the 'lib' folder (that contains only .dart files) instead of loading the project folder that contains 'pubspec.yaml, ios, linux, android, lib...'.

3 Comments

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
@From Review: Not really. Often the error Error: Not found: 'dart:ui' import 'dart:ui' is reported when you open the wrong folder in Visual Studio Code. Simply changing to your project root folder solves the problem.
"Warning: Interpreting this as package URI" also indicates that the intended project root was not clear. Another give away will be the execution target platform displayed on the status bar of VSCode will be missing, not selectable or just show up as Dart{}. All this indicates the correct project folder was not loaded.
0

This may be irrelevant in your case, but I had this issue when I tried to execute flutter pub run package:entry.

What solved the issue for me, was:

  • Check all the imports. You shouldn't create imports from inside the library that have the library name in it. Best to replace those with only relative imports.
  • I had an issue where two extension declarations were in one file. After I moved them into separate files, it worked.

Key thing is to try to narrow down the issue by importing only a few files and see when it starts to break. Yes, I know this is not a professional advice, but flutter projects behave weird sometimes.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.