ok
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import 'package:practice_engine/practice_engine.dart';
|
||||
import '../data/default_deck.dart';
|
||||
|
||||
/// Service for managing deck storage and retrieval.
|
||||
/// Currently uses in-memory storage. Can be extended to use persistent storage.
|
||||
class DeckStorage {
|
||||
static final DeckStorage _instance = DeckStorage._internal();
|
||||
factory DeckStorage() => _instance;
|
||||
DeckStorage._internal();
|
||||
|
||||
final Map<String, Deck> _decks = {};
|
||||
bool _initialized = false;
|
||||
|
||||
/// Initialize storage with default deck if empty
|
||||
void initialize() {
|
||||
if (_initialized) return;
|
||||
_initialized = true;
|
||||
|
||||
// Add default deck if no decks exist
|
||||
if (_decks.isEmpty) {
|
||||
final defaultDeck = DefaultDeck.deck;
|
||||
_decks[defaultDeck.id] = defaultDeck;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all decks
|
||||
List<Deck> getAllDecks() {
|
||||
initialize();
|
||||
return _decks.values.toList();
|
||||
}
|
||||
|
||||
/// Get a deck by ID
|
||||
Deck? getDeck(String id) {
|
||||
initialize();
|
||||
return _decks[id];
|
||||
}
|
||||
|
||||
/// Add or update a deck
|
||||
void saveDeck(Deck deck) {
|
||||
initialize();
|
||||
_decks[deck.id] = deck;
|
||||
}
|
||||
|
||||
/// Delete a deck
|
||||
void deleteDeck(String id) {
|
||||
_decks.remove(id);
|
||||
}
|
||||
|
||||
/// Check if a deck exists
|
||||
bool hasDeck(String id) {
|
||||
initialize();
|
||||
return _decks.containsKey(id);
|
||||
}
|
||||
|
||||
/// Get the number of decks
|
||||
int get deckCount {
|
||||
initialize();
|
||||
return _decks.length;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user