diff --git a/lib/screens/deck_import_screen.dart b/lib/screens/deck_import_screen.dart index b79bf29..b8e0c39 100644 --- a/lib/screens/deck_import_screen.dart +++ b/lib/screens/deck_import_screen.dart @@ -144,9 +144,14 @@ class _DeckImportScreenState extends State { } 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 { 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 { 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);