add a shit ton of feature for the custom srs

This commit is contained in:
Rene Kievits
2025-10-30 03:44:04 +01:00
parent b58a4020e1
commit ee4fd7ffc1
13 changed files with 787 additions and 311 deletions

View File

@@ -19,10 +19,25 @@ class CustomDeckRepository {
Future<void> addCard(CustomKanjiItem item) async {
final deck = await getCustomDeck();
deck.add(item);
await _saveDeck(deck);
await saveDeck(deck);
}
Future<void> _saveDeck(List<CustomKanjiItem> deck) async {
Future<void> updateCard(CustomKanjiItem item) async {
final deck = await getCustomDeck();
final index = deck.indexWhere((element) => element.characters == item.characters);
if (index != -1) {
deck[index] = item;
await saveDeck(deck);
}
}
Future<void> deleteCard(CustomKanjiItem item) async {
final deck = await getCustomDeck();
deck.removeWhere((element) => element.characters == item.characters);
await saveDeck(deck);
}
Future<void> saveDeck(List<CustomKanjiItem> deck) async {
final prefs = await SharedPreferences.getInstance();
final jsonList = deck.map((item) => item.toJson()).toList();
await prefs.setString(_key, json.encode(jsonList));