From d47887e1ec809732bc9c735f511c7a2411ead82f Mon Sep 17 00:00:00 2001 From: M Date: Mon, 18 Jul 2022 17:11:34 +0100 Subject: [PATCH] Add usage instruction to gift card. --- lib/ionia/ionia_gift_card.dart | 25 ++++++++++++-- .../cards/ionia_gift_card_detail_page.dart | 34 +++++++++++++++---- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/lib/ionia/ionia_gift_card.dart b/lib/ionia/ionia_gift_card.dart index df0ee6a52..cc8c3dbaa 100644 --- a/lib/ionia/ionia_gift_card.dart +++ b/lib/ionia/ionia_gift_card.dart @@ -1,5 +1,20 @@ +import 'dart:convert'; + import 'package:flutter/foundation.dart'; +class IoniaGiftCardInstruction { + IoniaGiftCardInstruction(this.header, this.body); + + factory IoniaGiftCardInstruction.fromJsonMap(Map element) { + return IoniaGiftCardInstruction( + element['header'] as String, + element['body'] as String); + } + + final String header; + final String body; +} + class IoniaGiftCard { IoniaGiftCard({ @required this.id, @@ -26,6 +41,11 @@ class IoniaGiftCard { @required this.logoUrl}); factory IoniaGiftCard.fromJsonMap(Map element) { + final decodedInstructions = json.decode(element['UsageInstructions'] as String) as Map; + final instruction = decodedInstructions['instruction'] as List; + final instructions = instruction + .map((dynamic e) =>IoniaGiftCardInstruction.fromJsonMap(e as Map)) + .toList(); return IoniaGiftCard( id: element['Id'] as int, merchantId: element['MerchantId'] as int, @@ -44,7 +64,8 @@ class IoniaGiftCard { isEmpty: element['IsEmpty'] as bool, logoUrl: element['LogoUrl'] as String, createdDateFormatted: element['CreatedDate'] as String, - lastTransactionDateFormatted: element['LastTransactionDate'] as String); + lastTransactionDateFormatted: element['LastTransactionDate'] as String, + usageInstructions: instructions); } final int id; @@ -54,7 +75,7 @@ class IoniaGiftCard { final String barcodeUrl; final String cardNumber; final String cardPin; - final Map usageInstructions; + final List usageInstructions; final Map balanceInstructions; final Map paymentInstructions; final String cardImageUrl; diff --git a/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart b/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart index 7f081453a..0d84bfaa9 100644 --- a/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart +++ b/lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart @@ -157,15 +157,35 @@ class IoniaGiftCardDetailPage extends BasePage { color: Theme.of(context).textTheme.body1.color, ), ), - SizedBox(height: 24), Align( alignment: Alignment.bottomLeft, - child: Text( - '', - style: textMedium( - color: Theme.of(context).textTheme.display2.color, - ), - ), + child: Container( + constraints: BoxConstraints( + maxHeight: MediaQuery.of(context).size.height * 0.5), + child: Expanded( + child: ListView.builder( + itemCount: viewModel.giftCard.usageInstructions.length, + itemBuilder: (_, int index) { + final instruction = viewModel.giftCard.usageInstructions[index]; + return Expanded( + child: Column( + children: [ + Padding( + padding: EdgeInsets.all(10), + child: Text( + instruction.header, + style: textLargeSemiBold( + color: Theme.of(context).textTheme.display2.color, + ), + )), + Text( + instruction.body, + style: textMedium( + color: Theme.of(context).textTheme.display2.color, + ), + ) + ])); + }))) ), SizedBox(height: 35), PrimaryButton(