Skip to content

Instantly share code, notes, and snippets.

@techpotatoes
Last active April 18, 2020 09:32
Show Gist options
  • Save techpotatoes/2c82805de766b8c4ac33da1aaaaffe1e to your computer and use it in GitHub Desktop.
Save techpotatoes/2c82805de766b8c4ac33da1aaaaffe1e to your computer and use it in GitHub Desktop.
Flutter development series - part3
repository.dart
abstract class Repository<T extends HiveObject> {
Future<void> save(T newObject);
Future<void> delete(T objectToDelete);
Future<List<T>> getAll();
}
loyaltycardrepository.dart
class LoyaltyCardRepository implements Repository<LoyaltyCard> {
LoyaltyCardBox loyaltyCardBox;
LoyaltyCardRepository(LoyaltyCardBox loyaltyCardBox) {
this.loyaltyCardBox = loyaltyCardBox;
}
@override
Future<List<LoyaltyCard>> getAll() async {
final box = await loyaltyCardBox.box;
return box.values.toList();
}
@override
Future<void> save(LoyaltyCard newObject) async {
final box = await loyaltyCardBox.box;
box.add(newObject);
}
@override
Future<void> delete(LoyaltyCard objectToDelete) async {
final box = await loyaltyCardBox.box;
box.delete(objectToDelete.key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment