Last active
April 18, 2020 09:32
-
-
Save techpotatoes/2c82805de766b8c4ac33da1aaaaffe1e to your computer and use it in GitHub Desktop.
Flutter development series - part3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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