Add usage instruction to gift card.

This commit is contained in:
M 2022-07-18 17:11:34 +01:00
parent 3b61edcc5a
commit d47887e1ec
2 changed files with 50 additions and 9 deletions

View file

@ -1,5 +1,20 @@
import 'dart:convert';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
class IoniaGiftCardInstruction {
IoniaGiftCardInstruction(this.header, this.body);
factory IoniaGiftCardInstruction.fromJsonMap(Map<String, dynamic> element) {
return IoniaGiftCardInstruction(
element['header'] as String,
element['body'] as String);
}
final String header;
final String body;
}
class IoniaGiftCard { class IoniaGiftCard {
IoniaGiftCard({ IoniaGiftCard({
@required this.id, @required this.id,
@ -26,6 +41,11 @@ class IoniaGiftCard {
@required this.logoUrl}); @required this.logoUrl});
factory IoniaGiftCard.fromJsonMap(Map<String, dynamic> element) { factory IoniaGiftCard.fromJsonMap(Map<String, dynamic> element) {
final decodedInstructions = json.decode(element['UsageInstructions'] as String) as Map<String, dynamic>;
final instruction = decodedInstructions['instruction'] as List<dynamic>;
final instructions = instruction
.map((dynamic e) =>IoniaGiftCardInstruction.fromJsonMap(e as Map<String, dynamic>))
.toList();
return IoniaGiftCard( return IoniaGiftCard(
id: element['Id'] as int, id: element['Id'] as int,
merchantId: element['MerchantId'] as int, merchantId: element['MerchantId'] as int,
@ -44,7 +64,8 @@ class IoniaGiftCard {
isEmpty: element['IsEmpty'] as bool, isEmpty: element['IsEmpty'] as bool,
logoUrl: element['LogoUrl'] as String, logoUrl: element['LogoUrl'] as String,
createdDateFormatted: element['CreatedDate'] as String, createdDateFormatted: element['CreatedDate'] as String,
lastTransactionDateFormatted: element['LastTransactionDate'] as String); lastTransactionDateFormatted: element['LastTransactionDate'] as String,
usageInstructions: instructions);
} }
final int id; final int id;
@ -54,7 +75,7 @@ class IoniaGiftCard {
final String barcodeUrl; final String barcodeUrl;
final String cardNumber; final String cardNumber;
final String cardPin; final String cardPin;
final Map<String, dynamic> usageInstructions; final List<IoniaGiftCardInstruction> usageInstructions;
final Map<String, dynamic> balanceInstructions; final Map<String, dynamic> balanceInstructions;
final Map<String, dynamic> paymentInstructions; final Map<String, dynamic> paymentInstructions;
final String cardImageUrl; final String cardImageUrl;

View file

@ -157,15 +157,35 @@ class IoniaGiftCardDetailPage extends BasePage {
color: Theme.of(context).textTheme.body1.color, color: Theme.of(context).textTheme.body1.color,
), ),
), ),
SizedBox(height: 24),
Align( Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
child: Text( child: Container(
'', constraints: BoxConstraints(
style: textMedium( maxHeight: MediaQuery.of(context).size.height * 0.5),
color: Theme.of(context).textTheme.display2.color, 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), SizedBox(height: 35),
PrimaryButton( PrimaryButton(