I use model of places where I have File object to store the path of images taken by device camera.
I want to store File(image.path) in Hive. But I get :
Unhandled Exception: HiveError: Cannot write, unknown type: _File. Did you forget to register an adapter?
part 'place.g.dart';
@HiveType(typeId: 0)
class Place extends HiveObject {
@HiveField(0)
final String id;
@HiveField(1)
final String name;
@HiveField(2)
final File image;
@HiveField(3)
final Location? location;
Place(this.id, this.name, this.image, this.location);
}
part 'file.g.dart';
@HiveType(typeId: 1)
class ImageFile extends HiveObject {
@HiveField(3)
File file;
ImageFile(this.file);
}
I have initialized and registered the adapters as well.
final dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
Hive.registerAdapter(PlaceAdapter());
Hive.registerAdapter(LocationAdapter());
Hive.registerAdapter(ImageFileAdapter());```
Hive docs recommends to write your own TypeAdapter for other types other than primitive ones?
But I don't have an idea how to write TypeAdapter for File
thx