import 'dart:convert'; import 'package:mnemo_cards_common/mnemo_cards_common.dart'; void main() { final jsonString = ''' { "id": "5", "title": "Глаголы I спр.", "subtitle": "Verbos", "color": "#FFE90F13", "version": "19", "cards": [ { "id": 28, "image": "base64image", "mnemo": "слушать музыку {и скучать}", "original": "escuchar", "translation": "слушать", "transcription": null, "imageBack": null, "transcriptionMnemo": null, "back": null } ], "items": [ { "type": "spacer", "flex": 1, "height": 0.0 }, { "type": "text", "deeplink": "mnemocards://ad/open?key=5c59b1feb68eaf985a46bb36c51fc40918eb009838362d44af43aebb1f03f62d&id=5&type=pack", "subtitle": "Эту тему можно открыть, посмотрев рекламу", "hasBorder": false }, { "type": "spacer", "flex": 0, "height": 10.0 }, { "type": "spacer", "flex": 0, "height": 20.0 } ], "price": "100" } '''; try { final json = jsonDecode(jsonString) as Map; print('JSON decoded successfully'); final dto = CardPackBuyDto.fromJson(json); print('CardPackBuyDto created successfully'); print('ID: ${dto.id}'); print('Title: ${dto.title}'); print('Subtitle: ${dto.subtitle}'); print('Color: ${dto.color}'); print('Price: ${dto.price}'); print('Cards count: ${dto.cards.length}'); print('Items count: ${dto.items?.length}'); // Test items deserialization dto.items?.forEach((item) { print('Item type: ${item.type}'); if (item is TextItem) { print(' TextItem subtitle: ${item.subtitle}'); } else if (item is SpacerItem) { print(' SpacerItem flex: ${item.flex}, height: ${item.height}'); } }); } catch (e, s) { print('Error: $e'); print('StackTrace: $s'); } }