hive icon indicating copy to clipboard operation
hive copied to clipboard

Storing dart class and List<String> in it, List<String> not getting persisted

Open Dalakoti07 opened this issue 3 years ago • 0 comments

I have a class like following

Code sample

@HiveType(typeId: HiveConstants.APP_SETTING_INDEX)
class AppSettings {
  AppSettings({
    required this.localeString,
    required this.searchHistory,
  });

  @HiveField(0)
  String localeString;

  @HiveField(1, defaultValue: <String>['default'])
  List<String> searchHistory;

}

Now data persists as soon as app is opened, but as soon as app is closed List becomes empty []. This hive box already existed I just add one more field searchHistory with code as 1. localeString is persisted.

Do I need to use .flush() always, I have not been using .flush() and its working fine in all other places.

Version

  • Platform: Android
  • Flutter version: 3.0.0
  • hive hive: ^2.2.2 hive_flutter: ^1.1.0

Dalakoti07 avatar Aug 05 '22 08:08 Dalakoti07