【发布时间】:2021-10-14 14:03:49
【问题描述】:
我正在使用 Hive 模型,即使在我运行时,我也已将 @HiveType(typeId: x) 正确分配给每个类
flutter packages pub run build_runner build
我在为 typeId 2 到 10 的模型生成的文件中遇到错误,下面是错误,这些从 typeId 2 到 10 的模型是后来添加的,所以我必须删除以前生成的文件并重新运行命令,然后 Hive 生成TypeAdapters for Type 0 和 Type 1 即 Module 和 UserData 没有问题。
The type 'TypeAdapter' is declared with 0 type parameters, but 1 type arguments were given.
Try adjusting the number of type arguments to match the number of type
parameters.dart(wrong_number_of_type_arguments)
This issue is for only models with typeId:2 to typeId:10
下面是我使用@HiveType 和@HiveField 的模型,
文件 1 模型
@HiveType(typeId: 0)
class UserData {
@HiveField(0)
String token;
int userID;
@HiveField(1)
String firstName;
UserData({
this.userID,
this.firstName,
});
}
@HiveType(typeId: 1)
class Module {
@HiveField(0)
int moduleID;
@HiveField(1)
String moduleName;
Module({
this.moduleID,
this.moduleName,
});
}
文件 2 模型
@HiveType(typeId: 2)
class ExamData {
@HiveField(0)
int moduleID;
@HiveField(1)
int broadcastID;
ExamData(
{this.moduleID,
this.broadcastID,});
}
@HiveType(typeId: 3)
class Section {
@HiveField(0)
int sectionID;
@HiveField(1)
String title;
Section(
{this.sectionID,
this.title
});
}
@HiveType(typeId: 4)
class Question {
@HiveField(0)
int questionID;
@HiveField(1)
String title;
Question(
{this.questionID,
this.title});
}
@HiveType(typeId: 5)
class Type {
@HiveField(0)
int typeId;
@HiveField(1)
String name;
Type({this.typeId, this.name});
}
@HiveType(typeId: 6)
class Answer {
@HiveField(0)
int answerID;
@HiveField(1)
String title;
Answer({this.answerID, this.title});
}
@HiveType(typeId: 7)
class FileInfo {
@HiveField(0)
int fileID;
@HiveField(1)
String type;
FileInfo(
{this.fileID,
this.type});
}
@HiveType(typeId: 8)
class Meta {
@HiveField(0)
String tempFieldForHiveTest;
@HiveField(1)
List<Tag> tags;
Meta({this.tags, this.tempFieldForHiveTest: ""});
}
@HiveType(typeId: 9)
class Tag {
@HiveField(0)
int tagID;
@HiveField(1)
int moduleID;
Tag(
{this.tagID,
this.moduleID,});
}
@HiveType(typeId: 10)
class SectionStatus {
@HiveField(0)
Section section;
@HiveField(1)
bool isAttempted;
SectionStatus({this.section, this.isAttempted});
}
以下是我的开发依赖项
dev_dependencies:
hive_generator: ^1.1.1
build_runner: ^2.0.6
flutter_launcher_icons: ^0.9.2
【问题讨论】:
标签: android ios flutter dart hive