|
|
|
|
@ -144,9 +144,14 @@ class _DeckImportScreenState extends State<DeckImportScreen> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final parsedDeck = _parseDeckFromJson(_jsonController.text.trim());
|
|
|
|
|
if (parsedDeck.questions.isEmpty) {
|
|
|
|
|
throw FormatException('JSON deck must contain at least one question to merge');
|
|
|
|
|
if (parsedDeck == null || parsedDeck.questions.isEmpty) {
|
|
|
|
|
throw FormatException(
|
|
|
|
|
parsedDeck == null
|
|
|
|
|
? 'Failed to parse deck'
|
|
|
|
|
: 'JSON deck must contain at least one question to merge',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final deckToMerge = parsedDeck;
|
|
|
|
|
|
|
|
|
|
final deckStorage = DeckStorage();
|
|
|
|
|
final existingDecks = deckStorage.getAllDecksSync();
|
|
|
|
|
@ -189,7 +194,7 @@ class _DeckImportScreenState extends State<DeckImportScreen> {
|
|
|
|
|
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
|
|
|
|
final mergedQuestions = [
|
|
|
|
|
...selectedDeck.questions,
|
|
|
|
|
...parsedDeck.questions.asMap().entries.map((e) {
|
|
|
|
|
...deckToMerge.questions.asMap().entries.map((e) {
|
|
|
|
|
final q = e.value;
|
|
|
|
|
final i = e.key;
|
|
|
|
|
return q.copyWith(id: '${q.id}_merged_${timestamp}_$i');
|
|
|
|
|
@ -200,7 +205,7 @@ class _DeckImportScreenState extends State<DeckImportScreen> {
|
|
|
|
|
|
|
|
|
|
showTopSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
message: 'Added ${parsedDeck.questions.length} question(s) to "${selectedDeck.title}"',
|
|
|
|
|
message: 'Added ${deckToMerge.questions.length} question(s) to "${selectedDeck.title}"',
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
|