0

I made a model in which I go to get the various data, they are all ok except the 'card' in which I cannot save the data to its inside in my Model .. how can I save the data inside the 'card' of the Map you see in the picture?

card

    factory VoucherPdf.fromJson(Map<String, dynamic> json) {
    try {
      return VoucherPdf._(
        id: json.get('id') as int,
        orderId: json.get('order_id') as int,
        quoteId: json.get('quote_id') as int,
        createdAt: json['createdAt'] == null
            ? null
            : DateTime.parse(json.get('createdAt') as String),
        status: json.get('status') as int,
        card: json.get('card') as Map<String, dynamic>,
      );
    } catch (e) {
      logger.e('[VoucherPdf-fromJson] Deserializing error: ${e.oneline}');
      rethrow;
    }
  }
ste
  • 25
  • 6
  • Are you getting any error? Please share it if you are. – Josteve Jan 23 '22 at 15:23
  • @Josteve at the moment no error, but I cannot recall the data inside it, for example 'pdf'. i need to use the data in it but i can't recall it. – ste Jan 23 '22 at 15:28
  • How are you trying to access pdf? – Josteve Jan 23 '22 at 15:30
  • @Josteve final voucherCanUse = widget.voucher.id; Connection() .getGiftCardPdf( giftcardOrderId: voucherCanUse.toString(), userId: ContentBloc().state.userInfo.id.toString(), ) .then( (index) async { var prove = index?.card.m; }, ); i try with ' index?.card. ' but i not find pdf in my propriety.. – ste Jan 23 '22 at 15:49
  • 1
    Since card is a map, read the pdf like `index?.card['pdf']` and not `index?.card.pdf` – Josteve Jan 23 '22 at 15:51
  • @Josteve oh fine work thanks, this gives me a base64 in string .. from this I have to generate a pdf to view. do you know how I can do? – ste Jan 23 '22 at 16:00
  • Check https://stackoverflow.com/questions/55598481/how-to-decode-base64-pdf-string-in-flutter – Josteve Jan 23 '22 at 16:28
  • @Josteve thank you very much, all correct. if placed 'Index? .Card [' pdf '] and not index? .Card.pdf' I do what to put your answer as final to close the post :) – ste Jan 23 '22 at 16:31
  • I've added my answer. – Josteve Jan 23 '22 at 16:57

1 Answers1

1

Since card is a map, read the pdf like index?.card['pdf'] and not index?.card.pdf

Josteve
  • 11,459
  • 1
  • 23
  • 35