marco.pms.mobileapp/lib/view/payment/payment_screen.dart

81 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:marco/controller/payment/payment_controller.dart';
import 'package:get/get.dart';
class PaymentScreen extends StatelessWidget {
final double amount;
final String description;
const PaymentScreen({
super.key,
this.amount = 0.0,
this.description = "No description",
});
@override
Widget build(BuildContext context) {
final args = (Get.arguments ?? {}) as Map<String, dynamic>;
final double finalAmount = args['amount'] ?? amount;
final String finalDescription = args['description'] ?? description;
final paymentController = Provider.of<PaymentController>(context);
return Scaffold(
appBar: AppBar(
title: const Text("Payment"),
backgroundColor: Colors.blueAccent,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Description: $finalDescription",
style: const TextStyle(fontSize: 18),
),
const SizedBox(height: 8),
Text(
"Amount: ₹${finalAmount.toStringAsFixed(2)}",
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 40),
// ✅ Show loader when payment processing
Center(
child: paymentController.isProcessing
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: () async {
await paymentController.startPayment(
amount: finalAmount,
description: finalDescription,
context: context,
);
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 40, vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
backgroundColor: Colors.green,
),
child: const Text(
"Pay Now",
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
),
],
),
),
);
}
}