我之前根据需要向 Hive 类型添加了额外的 Hive 字段。然后我删除了 .g.dart 文件并重新生成它没有问题。
这次在添加了一个新的 Hive 字段后,我遇到了这个错误,我无法理解为什么
[INFO] Generating build script...
[INFO] Generating build script completed, took 424ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 73ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 968ms
[INFO] Running build...
[INFO] Running build completed, took 21ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 55ms
[SEVERE] hive_generator:hive_generator on lib/main.dart (cached):
This builder requires Dart inputs without syntax errors.
However, package:flutter_app_hive/main.dart (or an existing part) contains the following errors.
main.dart:33:3: Expected to find ';'.
main.dart:33:3: Expected an identifier.
Try fixing the errors and re-running the build.
[SEVERE] Failed after 92ms
pub finished with exit code 1
我已经尝试过flutter clean、flutter pub outdated、pub get等等……我一直收到这个错误。
在我的 pubspec.yaml 中,这工作得很好,直到我添加了最新的 Hive 字段。
dependencies:
flutter:
sdk: flutter
hive: ^2.0.2
hive_flutter: ^1.0.0
path_provider: ^2.0.1
curved_navigation_bar: ^0.3.7
video_player: ^1.0.1
font_awesome_flutter: ^8.5.0
badges: ^1.2.0
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.0.1
hive_generator: ^1.1.0
我发现了一篇关于降级分析器的旧帖子,但这会导致我正在使用的版本出现问题。
在 main.dart 中,第 33:3 行没有错误。它不应该有;按照建议。这在以前也很好用,所以我不知道为什么它现在是一个问题。我还在这里注释掉了代码,即使在第 33:3 行没有任何内容,我仍然收到相同的错误消息
如果我删除我添加的字段,我仍然会收到同样的错误。如果我从备份中恢复 .g.dart 文件,我可以像以前一样运行该应用程序。
对此的任何输入将不胜感激,因为它非常令人困惑
更新:
所以我尝试删除模型文件并完全重新创建它,然后生成.g.dart。我明白了:
[INFO] Generating build script...
[INFO] Generating build script completed, took 485ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 83ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 1.1s
[INFO] Running build...
[INFO] Running build completed, took 23ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 66ms
[INFO] Succeeded after 102ms with 0 outputs (0 actions)
我尝试保持文件原样,向以前的 Hive 类型添加了一个新的 Hive 字段并添加了一个 Hive 类型,但我没有生成任何内容。
我没有更改现有的 Hive 字段,我知道这会导致问题。新 Hive 字段和 Hive 类型被赋予下一个以前未使用过的数字。