isar / hive

Lightweight and blazing fast key-value database written in pure Dart.
Apache License 2.0
4.1k stars 406 forks source link

Hive not storing Object when App restarts??? #1008

Open mike1985dev opened 2 years ago

mike1985dev commented 2 years ago

Hello, in my Flutter App using Hive is all running correct till I restart the App. Then the box is empty and the Object is not stored? Till I restart the App again, all is working fine. The Object is generated with the build_runner

@HiveType(typeId: 0)
class Favorites extends HiveObject {
  @HiveField(0)
  List<MediaItem> mediaItems = [];
}

final document = await getApplicationDocumentsDirectory();
  Hive
    ..init(document.path)
    ..registerAdapter(FavoritesAdapter())

await Hive.openBox<Favorites>('favorites');
.......

Box<Favorites> box = Hive.box<Favorites>('favorites');
      Favorites fav = box.getAt(0) ?? Favorites();
      fav.mediaItems.insert(0, playlist[i]);

The data are stored and when I restart the App the Box is empty??? Thanks for helping!

PwS commented 2 years ago

similar case https://github.com/hivedb/hive/issues/1002

burekas7 commented 1 year ago

+1