Hive: About HiveType and its typeId

Created on 17 Dec 2020  ยท  5Comments  ยท  Source: hivedb/hive

I felt ambiguous with the explanation provided on the docs, should the typeId of @HiveType be unique per model? Or I could do it like this, for instance:

@HiveType(typeId: 0)
class ClassA extends HiveObject {}

@HiveType(typeId: 0)
class ClassB extends HiveObject {}

@HiveType(typeId: 0)
class ClassC extends HiveObject {}

Or it should be like this?

@HiveType(typeId: 0)
class ClassA extends HiveObject {}

@HiveType(typeId: 1)
class ClassB extends HiveObject {}

@HiveType(typeId: 2)
class ClassC extends HiveObject {}

Version

  • Platform: iOS, Android
  • Flutter version: 1.22.5
  • Hive version: ^1.4.4+1
question

All 5 comments

It must be unique! ๐Ÿ˜

Hi @mbaumgartenbr ! Thanks for answering, so the properway is like the 2nd snippet I defined above?

Yep ๐Ÿ™‚

I see.. Thanks for fast response, have a nice day! I'm closing it. ๐Ÿฑโ€๐Ÿ

Link -> https://docs.hivedb.dev/#/custom-objects/type_adapters?id=register-adapter
"Every type has a unique typeId which is used to find the correct adapter when a value is brought back from disk. All typeIds between 0 and 223 are allowed."

  1. This means I can have a maximum of 223 dart model classes ?
  2. I have to remember what's the last Type ID I used in my app, and increment accordingly ?
  3. If my app need more than 223 Model Classes then what should I do ?
Was this page helpful?
0 / 5 - 0 ratings

Related issues

yaymalaga picture yaymalaga  ยท  4Comments

MyoLinOo picture MyoLinOo  ยท  3Comments

azilvl picture azilvl  ยท  3Comments

jamesdixon picture jamesdixon  ยท  3Comments

sergiyvergun picture sergiyvergun  ยท  4Comments