feat: payment page

This commit is contained in:
efrilm 2025-09-04 21:47:54 +07:00
parent dc4fdf5fbf
commit c12e9bd188

View File

@ -2,8 +2,6 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../common/theme/theme.dart'; import '../../../../common/theme/theme.dart';
// Import your theme files here
// import 'theme.dart';
@RoutePage() @RoutePage()
class PaymentPage extends StatefulWidget { class PaymentPage extends StatefulWidget {
@ -14,125 +12,292 @@ class PaymentPage extends StatefulWidget {
} }
class _PaymentPageState extends State<PaymentPage> { class _PaymentPageState extends State<PaymentPage> {
// Sample saved payment methods data // Featured payment methods
final List<Map<String, dynamic>> savedPaymentMethods = [ final List<Map<String, dynamic>> featuredMethods = [
{ {
'id': '1', 'id': 'qris',
'type': 'credit_card', 'name': 'QRIS',
'name': 'Kartu Kredit', 'subtitle': null,
'details': '**** **** **** 1234', 'icon': 'assets/images/qris.png',
'cardType': 'Visa', 'iconColor': AppColor.black,
'expiryDate': '12/26', 'badge': 'Baru',
'isDefault': true, 'badgeColor': const Color(0xFFE57373),
'icon': Icons.credit_card,
},
{
'id': '2',
'type': 'credit_card',
'name': 'Kartu Debit',
'details': '**** **** **** 5678',
'cardType': 'Mastercard',
'expiryDate': '08/27',
'isDefault': false,
'icon': Icons.credit_card,
},
{
'id': '3',
'type': 'ewallet',
'name': 'DANA',
'details': '081234567890',
'cardType': 'E-Wallet',
'expiryDate': null,
'isDefault': false,
'icon': Icons.account_balance_wallet,
},
{
'id': '4',
'type': 'ewallet',
'name': 'GoPay',
'details': '081234567890',
'cardType': 'E-Wallet',
'expiryDate': null,
'isDefault': false,
'icon': Icons.account_balance_wallet,
},
{
'id': '5',
'type': 'bank_account',
'name': 'BCA',
'details': '**** **** 9012',
'cardType': 'Bank Account',
'expiryDate': null,
'isDefault': false,
'icon': Icons.account_balance,
}, },
]; ];
Widget _buildPaymentCard(Map<String, dynamic> payment) { // Main payment categories
final List<Map<String, dynamic>> paymentCategories = [
{
'id': 'credit_card',
'name': 'Kartu Kredit',
'subtitle':
'Minimal pembayaran Rp 10.000 dan mendukung Kartu Berlogo Visa, Mastercard dan JCB',
'icon': Icons.credit_card,
'iconColor': const Color(0xFF2E7D32),
'hasArrow': false,
},
];
// Other payment methods
final List<Map<String, dynamic>> otherMethods = [
{
'id': 'gopay',
'name': 'Gopay',
'subtitle': 'Aktifkan Sekarang',
'logo': 'assets/images/gopay.png',
'iconColor': const Color(0xFF00AA5B),
'hasArrow': true,
},
{
'id': 'dana',
'name': 'Dana',
'subtitle': 'Aktifkan Sekarang',
'logo': 'assets/images/dana.png',
'iconColor': const Color(0xFF118EEA),
'hasArrow': true,
},
{
'id': 'blu',
'name': 'blu',
'subtitle': 'Aktifkan Sekarang',
'logo': 'assets/images/blu.png',
'iconColor': const Color(0xFF00D4FF),
'hasArrow': true,
},
{
'id': 'shopeepay',
'name': 'ShopeePay',
'subtitle': 'Aktifkan Sekarang',
'logo': 'assets/images/shopeepay.png',
'iconColor': const Color(0xFFEE4D2D),
'hasArrow': true,
},
{
'id': 'ovo',
'name': 'OVO',
'subtitle': 'Aktifkan Sekarang',
'logo': 'assets/images/ovo.png',
'iconColor': const Color(0xFF4C3EC9),
'hasArrow': true,
},
];
Widget _buildFeaturedCard(Map<String, dynamic> method) {
return Container( return Container(
decoration: const BoxDecoration( margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColor.white, color: AppColor.white,
border: Border(bottom: BorderSide(color: AppColor.border)), borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColor.border.withOpacity(0.3)),
), ),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row( child: Row(
children: [ children: [
// Logo placeholder
Container( Container(
width: 48, width: 40,
height: 48, height: 24,
decoration: BoxDecoration( decoration: BoxDecoration(
color: AppColor.background, color: AppColor.black,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(4),
border: Border.all(color: AppColor.border), ),
child: Center(
child: Text(
method['name'],
style: AppStyle.sm.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w700,
fontSize: 10,
),
),
), ),
child: Icon(payment['icon'], color: AppColor.primary, size: 24),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Expanded( Text(
method['name'],
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.textPrimary,
),
),
const Spacer(),
if (method['badge'] != null)
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: method['badgeColor'],
borderRadius: BorderRadius.circular(12),
),
child: Text(
method['badge'],
style: AppStyle.sm.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w600,
),
),
),
],
),
);
}
Widget _buildCategoryCard(Map<String, dynamic> category) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColor.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColor.border.withOpacity(0.3)),
),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
children: [ children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: category['iconColor'].withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
category['icon'],
color: category['iconColor'],
size: 20,
),
),
const SizedBox(width: 16),
Text( Text(
payment['name'], category['name'],
style: AppStyle.md.copyWith( style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: AppColor.textPrimary, color: AppColor.textPrimary,
), ),
), ),
], ],
), ),
const SizedBox(height: 4), if (category['subtitle'] != null) ...[
Row( const SizedBox(height: 12),
Text(
category['subtitle'],
style: AppStyle.md.copyWith(
color: const Color(0xFF4CAF50),
height: 1.4,
),
),
],
],
),
);
}
Widget _buildPaymentMethodCard(Map<String, dynamic> method) {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
// Handle method selection
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
decoration: const BoxDecoration(
color: AppColor.white,
border: Border(
bottom: BorderSide(color: Color(0xFFF5F5F5), width: 1),
),
),
child: Row(
children: [
// Method logo/icon
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
),
child: method['logo'] != null
? ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.asset(
method['logo'],
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return _buildFallbackIcon(method);
},
),
)
: _buildFallbackIcon(method),
),
const SizedBox(width: 16),
// Method info
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
payment['cardType'], method['name'],
style: AppStyle.sm.copyWith( style: AppStyle.lg.copyWith(
color: AppColor.textSecondary, fontWeight: FontWeight.w600,
color: AppColor.textPrimary,
), ),
), ),
if (payment['expiryDate'] != null) ...[ if (method['subtitle'] != null) ...[
const SizedBox(height: 2),
Text( Text(
'', method['subtitle'],
style: AppStyle.sm.copyWith( style: AppStyle.md.copyWith(color: AppColor.textLight),
color: AppColor.textSecondary,
),
),
Text(
'Exp: ${payment['expiryDate']}',
style: AppStyle.sm.copyWith(
color: AppColor.textSecondary,
),
), ),
], ],
], ],
), ),
),
// Arrow icon
if (method['hasArrow'] == true)
const Icon(
Icons.chevron_right,
color: AppColor.textLight,
size: 20,
),
], ],
), ),
), ),
], ),
);
}
Widget _buildFallbackIcon(Map<String, dynamic> method) {
String initial = method['name'][0].toUpperCase();
Color backgroundColor = method['iconColor'] ?? AppColor.primary;
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: backgroundColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Text(
initial,
style: AppStyle.md.copyWith(
color: backgroundColor,
fontWeight: FontWeight.w700,
),
),
),
);
}
Widget _buildSectionHeader(String title) {
return Padding(
padding: const EdgeInsets.fromLTRB(20, 24, 20, 8),
child: Text(
title,
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w700,
color: AppColor.textPrimary,
), ),
), ),
); );
@ -141,78 +306,40 @@ class _PaymentPageState extends State<PaymentPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: AppColor.background, backgroundColor: const Color(0xFFFAFAFA),
appBar: AppBar(title: Text('Metode Pembayaran')), appBar: AppBar(title: Text('Metode Pembayaran')),
body: savedPaymentMethods.isEmpty body: SingleChildScrollView(
? _buildEmptyState()
: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: savedPaymentMethods.length,
itemBuilder: (context, index) {
return _buildPaymentCard(savedPaymentMethods[index]);
},
),
),
],
),
);
}
Widget _buildEmptyState() {
return Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Icon(Icons.payment_outlined, size: 80, color: AppColor.textLight),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( // Featured methods
'Belum Ada Metode Pembayaran', ...featuredMethods.map((method) => _buildFeaturedCard(method)),
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w600, const SizedBox(height: 16),
color: AppColor.textSecondary,
// Payment categories
...paymentCategories.map(
(category) => _buildCategoryCard(category),
),
// Section header for other methods
_buildSectionHeader('Metode Pembayaran Lainnya'),
// Other payment methods
Container(
decoration: const BoxDecoration(color: AppColor.white),
child: Column(
children: otherMethods
.map((method) => _buildPaymentMethodCard(method))
.toList(),
), ),
), ),
const SizedBox(height: 8),
Text(
'Tambahkan kartu atau e-wallet untuk\nmemudahkan proses pembayaran',
textAlign: TextAlign.center,
style: AppStyle.md.copyWith(color: AppColor.textLight, height: 1.4),
),
const SizedBox(height: 32), const SizedBox(height: 32),
SizedBox(
width: 220,
height: 48,
child: ElevatedButton(
onPressed: () {
// Navigate to add payment method form
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.primary,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.add, color: AppColor.white, size: 20),
const SizedBox(width: 8),
Text(
'Tambah Pembayaran',
style: AppStyle.md.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w600,
),
),
], ],
), ),
), ),
),
],
),
); );
} }
} }