You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Question
How to avoid duplicating objects in datastore?
What is the best practice let Hive know that the object must be overridden or ignored instead of duplicating.
Future<List> getCountries() async {
final List countries = [];
final Box box = await openDataBox();
countries.addAll(box.values.toList());
return countries;
}
Version
Platform: iOS, Android, Web
Flutter version: [ 2.5.3]
Hive version: [2.0.4]
The content you are editing has changed. Please copy your edits and refresh the page.
If the data is not always new but you want to keep track of old data do: Future addCountries(List countries) async { final box = await openDataBox(); final existing = await getCountries(); // This returns the data you have already stored final result = existing.addAll(countries).toSet(); // This removes duplicates await box.addAll(result); }
Question
How to avoid duplicating objects in datastore?
What is the best practice let Hive know that the object must be overridden or ignored instead of duplicating.
Code sample
Future addCountries(List countries) async {
final Box box = await openDataBox();
box.addAll(countries);
}
Future<List> getCountries() async {
final List countries = [];
final Box box = await openDataBox();
countries.addAll(box.values.toList());
return countries;
}
Version
Tasks
The text was updated successfully, but these errors were encountered: