flutter 为什么build_runner watch命令不起作用?

6gpjuf90  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(192)

我有这个flutter项目,我一直在工作,我需要代码生成的各种原因,如riverpod供应商和冻结模型。所以我使用build_runner包来生成这个.g.dart文件,但是当我运行dart run build_runner watch时,我突然得到这个错误:

[INFO] Generating build script completed, took 152ms
[WARNING] ../../../../../.pub-cache/hosted/pub.dev/riverpod_generator-3.0.0-dev.4/lib/src/templates/family.dart:230:48: Error: The getter 'metadata' isn't defined for the class 'AstNode'.
 - 'AstNode' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../../../../.pub-cache/hosted/pub.dev/analyzer-6.2.0/lib/src/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'metadata'.
    final meta = metaAnnotations(provider.node.metadata);
                                               ^^^^^^^^
[INFO] Precompiling build script... completed, took 625ms
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

我已经看到了关于这个问题的几个帖子,但任何建议的答案似乎都有效。所以我尝试了几件事:dart run build_runner build --delete-conflicting-outputs删除pubspec.lock文件flutter cleanflutter pub get使用flutter pub upgrade将软件包升级到最新版本添加analyzer依赖包,如一篇文章所建议。尝试dart run build_runner doctor,但得到相同的输出。我还尝试了flutter chache repairflutter pub get,并手动删除该高速缓存存储int .dart_tool/目录,但没有任何工作。我已经被困在这几个小时没有用,我不知道什么可能是错的。这是我的pubscpec.yaml文件

name: myapp
description: A new Flutter project.
publish_to: none
version: 1.0.0+1
environment:
  sdk: '>=3.0.5 <4.0.0'
  flutter: ">=3.0.0"
  
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  flutter_riverpod: ^2.3.6
  riverpod_annotation: ^2.2.0
  analyzer:
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  riverpod_generator: ^3.0.0-dev.3
  riverpod_lint: ^2.3.0
  build_runner: ^2.4.6
flutter:
  assets:
    - lib/shared/assets/images/
  fonts:
    - family: Mont-Bold
      fonts:
        - asset: lib/shared/assets/fonts/Mont-Bold.otf
    - family: Mont-SemiBold
      fonts:
        - asset: lib/shared/assets/fonts/Mont-SemiBold.otf
    - family: Mont-Heavy
      fonts:
        - asset: lib/shared/assets/fonts/Mont-Heavy.otf
uses-material-design: true
g9icjywg

g9icjywg1#

riverpod_generator3.0.0-dev.4版本有问题,所以暂时可以通过删除^来严格使用3.0.0-dev.3

dev_dependencies:
  riverpod_generator: 3.0.0-dev.3

相关问题