import and merge 2

This commit is contained in:
gitea
2026-02-01 22:43:41 +01:00
parent 25b005db3a
commit afe86721ed
+9 -4
View File
@@ -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);