Flutter:构建运行器抛出预编译错误

Flutter: build runner throws a precompile error

我正在使用 analyser 1.7.1。最新的 build_runner 构建命令生成以下错误。

flutter packages pub run build_runner build Failed to precompile build_runner:build_runner: ../../../sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.1/lib/src/error/best_practices_verifier.dart:1998:14: Error: A non-null value must be returned since the return type 'String' doesn't allow null. String get displayString {

通常的 flutter cleanpub cache repair 命令似乎无法解决问题,displayString 也没有出现在我的代码库中。

an issue 9 天前营业。这是关键部分:

Right now, the current state of affairs is that:

  • package:analyzer 1.7.0 requires package:meta ^1.4.0
  • package:analyzer 1.7.1 has the same contents as 1.7.0, but requires package:meta ^1.3.0
  • Flutter stable pins package:meta to 1.3.0

I'm uncertain how we're running into the exceptions above - the two most recent versions of analyzer are pretty explicit about which version of meta they need.

@edlman do you have any dependency_overrides in your pubspec?

you're right, I'm using 3rd party pkgs which depend on meta 1.4.0 so I put it to dependency_overrides to solve the collision. It didn't come to my mind it cause such a problem. I've changed the override to 1.3.0, it works fine, no problem yet

所以我建议检查您的 pubspec 中是否也有 dependency_overrides。

analyser 1.7.1 有问题。

添加

dependency_overrides:
  analyzer: 1.7.0

pubspec.yaml

raina77ow 的回答中有更多详细信息。