flutter-web: build_runner getter 'typeArguments' 没有为类 'Annotation' 错误定义

Posted

技术标签:

【中文标题】flutter-web: build_runner getter \'typeArguments\' 没有为类 \'Annotation\' 错误定义【英文标题】:flutter-web: build_runner getter 'typeArguments' isn't defined for the class 'Annotation' errorflutter-web: build_runner getter 'typeArguments' 没有为类 'Annotation' 错误定义 【发布时间】:2021-06-06 03:36:18 【问题描述】:

在我的 web flutter 项目中,我正在尝试构建它:

flutter  packages pub run build_runner build --delete-conflicting-outputs

但我不知道为什么会出现这个错误:

Failed to precompile build_runner:build_runner:
../../../Sdk/flutter/.pub-cache/hosted/pub.dartlang.org/dart_style-1.3.14/lib/src/source_visitor.dart:302:16: Error: The getter 'typeArguments' isn't defined for the class 'Annotation'.
 - 'Annotation' is from 'package:analyzer/dart/ast/ast.dart' ('../../../Sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.40.4/lib/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'typeArguments'.
    visit(node.typeArguments);

我确定之前没问题,analyzer-0.40.4 也没问题,尽管更换分析仪后我还是遇到了这个错误。我正在使用 SDK 2.7.0 版:

environment:
  sdk: ">=2.7.0 <3.0.0"

dependency_overrides:
  analyzer: 0.40.4
  build_resolvers: '1.4.4'

这是颤振医生:

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Linux, locale en_US.UTF-8)                                                                                                                                                                                      [✓] android toolchain - develop for Android devices (Android SDK version 30.0.0-rc1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.54.1)
[✓] Connected device (2 available)

• No issues found!

我还没有迁移到新的 Flutter 版本。

【问题讨论】:

【参考方案1】:

我不知道它是否有用但我终于解决了这个问题,我提出了我的解决方案可能会帮助一些人:

这就是所有的变化:

dependency_overrides:
  # analyzer: 0.40.4  // comment this
  build_resolvers: '1.4.2' // this

dev_dependencies:
  flutter_localizations:
    sdk: flutter
  build_runner: 1.10.4 // this

【讨论】:

以上是关于flutter-web: build_runner getter 'typeArguments' 没有为类 'Annotation' 错误定义的主要内容,如果未能解决你的问题,请参考以下文章

无法预编译 build_runner:build_runner:

如何防止platformViewRegistry出错[flutter-web]

如何在小部件的容器内显示 pdf [flutter-web]

flutter-web:通过 Location 插件获取 web 上的位置

Flutter-web:浏览器刷新时提供者状态丢失

图像列表不显示在 Flutter-web 中