Flutter hive:无法生成适配器文件

Tho*_*myB 7 flutter flutter-hive

我有一个这样的模型:

\n
import 'package:uuid/uuid.dart';\nimport 'package:hive/hive.dart';\n\npart 'config_item.g.dart';\n\n@HiveType()\nclass ConfigItem {\n  @HiveField(0)\n  String _id; // this can be a uuid or a MongoDB ObjectID\n  @HiveField(1)\n  final String deviceName;\n....\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我喜欢生成适配器文件,但它不想这样做!当我打电话时flutter packages pub run build_runner build --delete-conflicting-outputs我得到以下输出:

\n
flutter packages pub run build_runner build  --delete-conflicting-outputs                main  \xe2\x9c\xad \xe2\x9c\x88\n[INFO] Generating build script...\n[INFO] Generating build script completed, took 399ms\n\n[SEVERE] Nothing can be built, yet a build was requested.\n[INFO] Initializing inputs\n[INFO] Reading cached asset graph...\n[INFO] Reading cached asset graph completed, took 45ms\n\n[INFO] Checking for updates since last build...\n[INFO] Checking for updates since last build completed, took 399ms\n\n[INFO] Running build...\n[INFO] Running build completed, took 3ms\n\n[INFO] Caching finalized dependency graph...\n[INFO] Caching finalized dependency graph completed, took 35ms\n\n[INFO] Succeeded after 53ms with 0 outputs (0 actions)\n
Run Code Online (Sandbox Code Playgroud)\n

在我的pubspec.yaml我有:

\n
environment:\n  sdk: ">=2.12.0 <3.0.0"\n\ndependencies:\n  flutter:\n    sdk: flutter\n\n\n  # The following adds the Cupertino Icons font to your application.\n  # Use with the CupertinoIcons class for iOS style icons.\n  cupertino_icons: ^1.0.2\n  bottom_navy_bar: ^6.0.0\n  get_it: ^7.2.0\n  get_it_mixin: ^3.1.3\n  servicestack: ^2.0.0\n  font_awesome_flutter: ^9.1.0\n  hive: ^2.0.4\n  hive_flutter: ^1.1.0\n  path_provider: ^2.0.3\n  uuid: ^3.0.4\n\ndev_dependencies:\n  flutter_test:\n    sdk: flutter\n  build_runner:\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试了各种各样的事情,比如

\n
    \n
  • 删除 .dart_tool 文件夹
  • \n
  • 添加*.g.dart.gitignore
  • \n
  • flutter clean
  • \n
  • 我在网上搜索时发现了更多。
  • \n
\n

但没有任何帮助!知道缺少什么吗?

\n

我正在使用最新(稳定)版本的 flutter、dart SDK 和 AndroidStudio。

\n

Ari*_*eet 11

运行这个命令:

flutter packages pub run build_runner build
Run Code Online (Sandbox Code Playgroud)

但在此之前,您必须导入生成器。

示例:如果您的文件名是project_database.dart,则在该文件中:

进口,

import 'package:hive/hive.dart';
part 'project_database.g.dart'; //this will show an error initially but if
 // you run the above command, it will generate the generator file
Run Code Online (Sandbox Code Playgroud)


Zai*_*rza 6

我遇到了同样的问题,但我失踪了hive_generator: ^1.1.1我在原始文档中没有找到它。

特别感谢@Denny Mueller 的评论