0

我之前根据需要向 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 类型被赋予下一个以前未使用过的数字。

4

2 回答 2

0

source_gen: 1.0.3在 pubspec.yaml 中设置对我有帮助。

于 2021-08-17T08:43:45.340 回答
0

所以我没有解决这个问题,但是为了解决这个问题,我创建了一个新的颤振项目,复制了我的代码,除了任何生成的文件。然后我能够在添加新的 Hive 字段和 hive 类型后生成新的类型适配器。也许在我之前的项目中有些东西被破坏了。不知道为什么颤振清洁不能解决这个问题。但也许这会帮助有人陷入同样的​​问题。

于 2021-05-14T13:56:19.503 回答