How to save a List<Object> and retrieve using Hive?

You have to anotate your object with @HiveType(). And have to register your object Hive.registerAdapter(WallpaperAdapter(), 0);.

And yet, do you have part 'wallpaper.g.dart'; to generate the needed code?

EDITED: First of all import the dependencies on your pubspec:

dependencies:
  hive: ^[version]
  hive_flutter: ^[version]

dev_dependencies:
  hive_generator: ^[version]
  build_runner: ^[version]

The Hive.registerAdapter(MyObjectAdapter(), 0); you should put inside your main.dart function. Right before runApp

Your HiveObject should have annotations like that:

@HiveType()
class Person extends HiveObject {
  @HiveField(0);
  String name;

  @HiveField(1);
  int age;
}

Put this command near your imports part 'person.g.dart'; and run the code generation on your terminal. flutter packages pub run build_runner build.

Hive function with code generation, so this command will generate the file you need


I solved the problem by including an actual ID on HiveType. Like this:

  @HiveType(typeId: 0)
  class SoundSingle {

    @HiveField(0)
    final String name;

    @HiveField(1)
    final String fileName;

    @HiveField(2)
    int volume;

    SoundSingle(this.name,this.fileName, this.volume);
}

More HiveType models need to increment the number. So each value is unique ( and I guess sequential, but I did not test on that ) .