Необработанное исключение: тип String не является подтипом типа int в приведении типа

Я использую hive как Db своего приложения, я создал адаптер своего класса, но когда я пытаюсь запустить свое приложение, я принял исключение ниже ...................... .................................................. .................................................. ..................................................

      E/flutter (14408): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type 'String' is not a subtype of type 'int' in type cast
E/flutter (14408): #0      SubCategoryModelAdapter.read (package:lezzet_kitabi/subCategoryModel.g.dart:20:32)
E/flutter (14408): #1      BinaryReaderImpl.read (package:hive/src/binary/binary_reader_impl.dart:326:33)
E/flutter (14408): #2      BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:274:26)
E/flutter (14408): #3      FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:21:26)
E/flutter (14408): #4      FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:42:12)
E/flutter (14408): <asynchronous suspension>
E/flutter (14408): #5      StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:86:11)
E/flutter (14408): <asynchronous suspension>
E/flutter (14408): #6      HiveImpl._openBox (package:hive/src/hive_impl.dart:113:9)
E/flutter (14408): <asynchronous suspension>
E/flutter (14408): #7      HiveImpl.openBox (package:hive/src/hive_impl.dart:142:12)
E/flutter (14408): <asynchronous suspension>
E/flutter (14408): #8      main (package:lezzet_kitabi/main.dart:28:3)
E/flutter (14408): <asynchronous suspension>
E/flutter (14408): 

Разделяю класс и его адаптер

      part 'subCategoryModel.g.dart';


@HiveType(typeId : 1)
class SubCategoryModel extends HiveObject{
  SubCategoryModel({
    this.subCategoryId,
    this.subCategoryImagePath,
    this.subCategoryName,
    this.categoryColor,
    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;

}

      // 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, dynamic>{
      for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
    };
    return SubCategoryModel(
      subCategoryId: fields[3] as int,
      subCategoryImagePath: fields[4] as String,
      subCategoryName: fields[5] as String,
      categoryColor: fields[0] as int,
      recipeId: fields[1] as double,
      ingredients: (fields[6] as List)?.cast<Ingredient>(),
      recipePhotoDir: fields[7] as String,
      recordedVoiceDir: fields[8] as String,
    )..isCompleted = fields[2] as bool;
  }

  @override
  void write(BinaryWriter writer, SubCategoryModel obj) {
    writer
      ..writeByte(9)
      ..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);
  }

  @override
  int get hashCode => typeId.hashCode;

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

Вы можете мне помочь, спасибо.

0 ответов

Другие вопросы по тегам