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