我有这样一个模型:
import 'package:uuid/uuid.dart';
import 'package:hive/hive.dart';
part 'config_item.g.dart';
@HiveType()
class ConfigItem {
@HiveField(0)
String _id; // this can be a uuid or a MongoDB ObjectID
@HiveField(1)
final String deviceName;
....
}
我想生成适配器文件,但它不想这样做!当我调用flutter packages pub run build_runner build --delete-conflicting-outputs
时,我得到以下输出:
flutter packages pub run build_runner build --delete-conflicting-outputs main ✭ ✈
[INFO] Generating build script...
[INFO] Generating build script completed, took 399ms
[SEVERE] Nothing can be built, yet a build was requested.
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 45ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 399ms
[INFO] Running build...
[INFO] Running build completed, took 3ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 35ms
[INFO] Succeeded after 53ms with 0 outputs (0 actions)
在我的pubspec.yaml
中,我有:
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
bottom_navy_bar: ^6.0.0
get_it: ^7.2.0
get_it_mixin: ^3.1.3
servicestack: ^2.0.0
font_awesome_flutter: ^9.1.0
hive: ^2.0.4
hive_flutter: ^1.1.0
path_provider: ^2.0.3
uuid: ^3.0.4
dev_dependencies:
flutter_test:
sdk: flutter
build_runner:
我试过各种方法
- 删除.dart_tool文件夹
- 将
*.g.dart
添加到.gitignore
flutter clean
- 还有很多我在网上搜到的。
但无济于事知道少了什么吗?
我正在使用flutter、dart SDK和AndroidStudio的最新(稳定)版本。
8条答案
按热度按时间hgncfbus1#
运行此命令:
但在此之前,您将不得不导入生成器。
示例:如果文件名为project_database. dart,则在该文件中:
进口、
mcdcgff02#
我遇到了同样的问题,但是我缺少
hive_generator: ^1.1.1
,我在原来的Docs中没有找到它。特别感谢@Denny Mueller的评论
jjjwad0x3#
试试这个,
9vw9lbht4#
我有同样的问题。我解决了保存我的变化在pubspec.yaml。只需按ctrl + s在pubspec.yaml然后运行flutter包pub运行build_runner再次建立。
mrzz3bfm5#
得到零件后,保存它,错误就消失了
另外在ur dev_dependecies中添加hive_generator。
hive_generator包可以为几乎所有类自动生成TypeAdapter。
如果您有任何其他问题,请参阅此处
0vvn1miw6#
为@HiveType给予类型ID。
在您的案例中:
rdrgkggo7#
hof1towb8#
不要忘记在dev_dependencies中添加hive_generator。