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

前端 未结 4 1821
终归单人心
终归单人心 2020-12-06 16:10

When I start a debugging session (pressing F5) I receive the following messages:

dart:ui:1: Error: Not found: dart:ui.
Exited (sigterm)

The

相关标签:
4条回答
  • 2020-12-06 16:44

    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 讨论(0)
  • 2020-12-06 16:44

    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.

    0 讨论(0)
  • 2020-12-06 16:46

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

    0 讨论(0)
  • 2020-12-06 16:55

    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.

    0 讨论(0)
提交回复
热议问题