Flutter错误:Dart库 ‘dart:ui’ 在此平台上不可用

huangapple go评论73阅读模式
英文:

Flutter Error: Dart library 'dart:ui' is not available on this platform

问题

[运行中] dart "c:\Users\PC\AndroidStudioProjects\FlutterXD\lib\main.dart";
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: 错误: Dart库'dart:ui'在此平台上不可用。
import 'dart:ui' as ui show Canvas, Paint, Path;
^
上下文: 此不可用的库'dart:ui'通过这些包导入:

package:flutterxd => package:flutter => dart:ui
...
(某些)这些导入的详细路径:

package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/assertions.dart => package/flutter/src/foundation/diagnostics.dart => package/flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/binding.dart => dart:ui
package:flutterxd/main.dart => package/flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/binding.dart => package/flutter/src/foundation/assertions.dart => package/flutter/src/foundation/diagnostics.dart => package/flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/binding.dart => package/flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/change_notifier.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/change_notifier.dart => package/flutter/src/foundation/assertions.dart => package/flutter/src/foundation/diagnostics.dart => package/flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package/flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => package/flutter/src/foundation/diagnostics.dart => package/flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/change_notifier.dart => package:flutter/src/foundation/memory_allocations.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package/flutter/src/material/about.dart => package/flutter/foundation.dart => package/flutter/src/foundation/change_notifier.dart => package/flutter/src/foundation/memory_allocations.dart => package/flutter/src/foundation/assertions.dart => package/flutter/src/foundation/diagnostics.dart => package/flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package...

英文:
[Running] dart "c:\Users\PC\AndroidStudioProjects\FlutterXD\lib\main.dart"
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' as ui show Canvas, Paint, Path;
^
Context: The unavailable library 'dart:ui' is imported through these packages:
package:flutterxd => package:flutter => dart:ui
...
Detailed import paths for (some of) the these imports:
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/binding.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/binding.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/binding.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => package:flutter/src/foundation/memory_allocations.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => package:flutter/src/foundation/memory_allocations.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/change_notifier.dart => package:flutter/src/foundation/memory_allocations.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/key.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/memory_allocations.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/memory_allocations.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/foundation.dart => package:flutter/src/foundation/memory_allocations.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/scheduler.dart => package:flutter/src/scheduler/binding.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/scheduler.dart => package:flutter/src/scheduler/binding.dart => package:flutter/src/scheduler/priority.dart => package:flutter/foundation.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/scheduler.dart => package:flutter/src/scheduler/binding.dart => package:flutter/src/scheduler/priority.dart => package:flutter/foundation.dart => package:flutter/src/foundation/binding.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/scheduler.dart => package:flutter/src/scheduler/binding.dart => package:flutter/src/scheduler/priority.dart => package:flutter/foundation.dart => package:flutter/src/foundation/binding.dart => package:flutter/src/foundation/assertions.dart => package:flutter/src/foundation/diagnostics.dart => package:flutter/src/foundation/debug.dart => dart:ui
package:flutterxd/main.dart => package:flutter/material.dart => package:flutter/src/material/about.dart => package:flutter/scheduler.dart => package:flutter/src/scheduler/binding.dart => package:flutter/src/scheduler/priority.dart => package:flutter/foundation.dart => package:flutter/src/foundation/binding.dart => package:flutter/src/foundation/debug.dart => dart:ui
...
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' as ui;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/badge_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/banner_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
../../Documents/FlutterDev/flutter/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart:5:8: Error: Dart library 'dart:ui' is not available on this platform.
import 'dart:ui' show lerpDouble;
^
[Done] exited with code=254 in 13.502 seconds

NOTHING, i did try nothing

答案1

得分: 7

尝试禁用最近安装的扩展,并重新启动 VSC。在我的情况下,问题是由 "Code Runner" 扩展引起的。

英文:

Try to disable extensions you’ve installed lately and restart VSC. In my case the problem was caused by "Code Runner" extension

答案2

得分: 2

只需导入'package:flutter/material.dart'而不是dart:ui,如果要使用Canvas、Paint和Path等类。

清除导入'dart:ui',只需添加导入'package:flutter/material.dart'。

还要检查你的类是否扩展了CustomPainter。

示例:

import 'package:flutter/material.dart';

class PainterTest extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    // TODO: implement paint
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    // TODO: implement shouldRepaint
    throw UnimplementedError();
  }
}
英文:

If you want to use classes such as Canvas, Paint, and Path,
it is enough to import 'package:flutter/material.dart' instead of dart:ui.

Clear import 'dart:ui' as ui;
just add import 'package:flutter/material.dart';

Also check your class extends CustomPainter.

EX)

// import 'dart:ui' as ui;
import 'package:flutter/material.dart';
class PainterTest extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
// TODO: implement paint
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
// TODO: implement shouldRepaint
throw UnimplementedError();
}
}

答案3

得分: 2

检查已安装的扩展,如果有任何C++或Linux扩展,则卸载它们。在我的情况下,我卸载了CMake扩展,然后它就正常工作了。但请确保使用flutter doctor -v已设置好一切。

英文:

Check your intalled extensions if there are any c++ or linux extensions then uninstall them. In my case i uninstalled the CMake extension and then it worked. But make sure you have everything set up using flutter doctor -v

答案4

得分: 1

  1. 卸载 'Code Runner' 扩展。
  2. 然后重新启动 VSCode。
英文:

Same issue. Here is my solution:

1.Uninstall 'Code Runer' extension.
2.Then restart VSCode

答案5

得分: 0

我有相同的问题。
在Android Studio中,您的项目是一个DART项目,您需要将项目重新配置为Flutter项目,然后它应该可以正常工作。

英文:

I have the same issue.<br>
In android studio, your project is a DART Project, you need to reconfigure the project as Flutter project and it should work fine.

答案6

得分: 0

检查您的pubspec.yaml文件,看看是否有两个具有相似功能的依赖项,例如flutter_downloader和background_downloader。如果是这样,请注释掉其中一个。

英文:

Check your pubspec.yaml to see if there are two dependencies with similar functions, such as flutter_downloader and background_downloader. If so, just comment out one of them.

huangapple
  • 本文由 发表于 2023年2月6日 08:15:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356399.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定