微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

不支持的操作:无法添加到固定长度列表,在 Hive 中

如何解决不支持的操作:无法添加到固定长度列表,在 Hive 中

您好,我使用 Hive 来存储我的应用程序数据,当我运行代码时,我可以添加主类别,对于每个类别,我可以添加子类别。当我关闭应用程序并再次打开它时,我可以添加主类别,但是当我尝试为现有主类别添加一个子类别时,我无法添加一个新的子类别并且我面临一个错误'未处理的异常:不支持的操作:无法添加一个固定长度的列表',我该如何解决我一直卡住,请帮助

这是我的 categoryModel 和 subCategoryMoldel 类以及子类别屏幕。感谢您的帮助。

file = input("Enter a File Here:   ")
with open(file,"r") as f:
    lines = ""
    for line in f.readlines():
        lines = lines + line
print(lines)
part 'categoryModel.g.dart';

@HiveType(typeId : 0)
class CategoryModel extends HiveObject{
  CategoryModel(
      { this.categoryId,this.categoryImagePath,this.categoryName,this.categoryColor,this.subCategoryModels});

  @HiveField(0)
  final int categoryColor;

  @HiveField(1)
  List <SubCategoryModel> subCategoryModels;

  @HiveField(2)
  int categoryId;

  @HiveField(3)
  String categoryImagePath;

  @HiveField(4)
  String categoryName;

}
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'categoryModel.dart';

// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************

class CategoryModelAdapter extends TypeAdapter<CategoryModel> {
  @override
  final int typeId = 0;

  @override
  CategoryModel read(BinaryReader reader) {
    final numOfFields = reader.readByte();
    final fields = <int,dynamic>{
      for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),};
    return CategoryModel(
      categoryId: fields[2] as int,categoryImagePath: fields[3] as String,categoryName: fields[4] as String,categoryColor: fields[0] as int,subCategoryModels: (fields[1] as List)?.cast<SubCategoryModel>(),);
  }

  @override
  void write(BinaryWriter writer,CategoryModel obj) {
    writer
      ..writeByte(5)
      ..writeByte(0)
      ..write(obj.categoryColor)
      ..writeByte(1)
      ..write(obj.subCategoryModels)
      ..writeByte(2)
      ..write(obj.categoryId)
      ..writeByte(3)
      ..write(obj.categoryImagePath)
      ..writeByte(4)
      ..write(obj.categoryName);
  }

  @override
  int get hashCode => typeId.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this,other) ||
      other is CategoryModelAdapter &&
          runtimeType == other.runtimeType &&
          typeId == other.typeId;
}

part 'subCategoryModel.g.dart';


@HiveType(typeId : 1)
class SubCategoryModel extends HiveObject{
  SubCategoryModel({
    this.subCategoryId,this.subCategoryCardId,this.subCategoryImagePath,this.subCategoryName,this.recipeId,this.ingredients,this.recipePhotoDir,this.recordedVoiceDir});

  @HiveField(0)
  final int categoryColor;

  @HiveField(1)
  final double recipeId;

  @HiveField(2)
  bool isCompleted;

  @HiveField(3)
  int subCategoryId;

  @HiveField(4)
  String subCategoryImagePath;

  @HiveField(5)
  String subCategoryName;

  @HiveField(6)
  List <Ingredient> ingredients;

  @HiveField(7)
  String recipePhotoDir;

  @HiveField(8)
  String recordedVoiceDir;

  @HiveField(9)
  int subCategoryCardId;

}
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'subCategoryModel.dart';

// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************

class SubCategoryModelAdapter extends TypeAdapter<SubCategoryModel> {
  @override
  final int typeId = 1;

  @override
  SubCategoryModel read(BinaryReader reader) {
    final numOfFields = reader.readByte();
    final fields = <int,};
    print(fields[3]);
    print(fields[0]);
    return SubCategoryModel(
      subCategoryId: fields[3] as int,subCategoryImagePath: fields[4] as String,subCategoryName: fields[5] as String,recipeId: fields[1] as double,ingredients: (fields[6] as List)?.cast<Ingredient>(),recipePhotoDir: fields[7] as String,recordedVoiceDir: fields[8] as String,subCategoryCardId:fields[9] as int,)..isCompleted = fields[2] as bool;
  }

  @override
  void write(BinaryWriter writer,SubCategoryModel obj) {
    writer
      ..writeByte(10)
      ..writeByte(0)
      ..write(obj.categoryColor)
      ..writeByte(1)
      ..write(obj.recipeId)
      ..writeByte(2)
      ..write(obj.isCompleted)
      ..writeByte(3)
      ..write(obj.subCategoryId)
      ..writeByte(4)
      ..write(obj.subCategoryImagePath)
      ..writeByte(5)
      ..write(obj.subCategoryName)
      ..writeByte(6)
      ..write(obj.ingredients)
      ..writeByte(7)
      ..write(obj.recipePhotoDir)
      ..writeByte(8)
      ..write(obj.recordedVoiceDir)
      ..writeByte(9)
      ..write(obj.subCategoryCardId);
  }

  @override
  int get hashCode => typeId.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this,other) ||
      other is SubCategoryModelAdapter &&
          runtimeType == other.runtimeType &&
          typeId == other.typeId;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。