cardWidget method
Implementation
Widget cardWidget(BuildContext context, PaymentViewModel model) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Card(
elevation: 4,
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Column(
children: [
model.isWebView
? SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
child: WebViewWidget(controller: model.webViewController),
)
: Form(
key: model.formKey,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8),
Text(
model.isVisa ? 'Visa Payment' : 'MasterCard Payment',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
CachedNetworkImage(
imageUrl:
model.isVisa
? "https://smatpay.s3.af-south-1.amazonaws.com/visa.png"
: "https://smatpay.s3.af-south-1.amazonaws.com/master_card.png",
placeholder:
(context, url) => CircularProgressIndicator(),
// Placeholder while loading
errorWidget:
(context, url, error) => Icon(Icons.error),
// Error widget if image fails
fit: BoxFit.contain,
height: 50,
width:
100, // You can adjust this to your preferred fit
),
const SizedBox(height: 16),
buildAmountTextField(
'Amount',
true,
model,
amountController,
(value) => model.updateAmount(value),
null,
),
const SizedBox(height: 16),
buildTextField(
'Card Number',
false,
model,
(value) => model.updateCardNumber(value),
(value) =>
model.isVisa
? Validators.isVisaCard(value)
: Validators.isMasterCard(value),
),
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: buildTextField(
'MMYYYY',
false,
model,
(value) => model.updateExpiryDate(value),
Validators.isValidExpiry,
),
),
const SizedBox(width: 16),
Expanded(
child: buildTextField(
'CVV',
false,
model,
(value) => model.updateCVV(value),
Validators.isCardCvv,
),
),
],
),
const SizedBox(height: 16),
PaymentButton(model),
],
),
),
),
],
),
),
);
}