feat: voucher detail

This commit is contained in:
efrilm
2025-08-29 16:28:27 +07:00
parent 74d706b32a
commit 4dc56662c8
4 changed files with 574 additions and 246 deletions
@@ -1,8 +1,10 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import '../../../../../../common/theme/theme.dart';
import '../../../../../../common/ui/clipper/voucher_clipper.dart';
import '../../../../../../common/ui/painter/dashed_line_painter.dart';
import '../../../../../router/app_router.gr.dart';
class VoucherCard extends StatelessWidget {
final String title;
@@ -19,188 +21,194 @@ class VoucherCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 12,
offset: Offset(0, 4),
spreadRadius: 0,
),
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 6,
offset: Offset(0, 2),
spreadRadius: 0,
),
],
),
child: ClipPath(
clipper: VoucherClipper(),
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: [
// Main Content
Padding(
padding: EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: AppStyle.lg.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 4),
Text(
subtitle,
style: AppStyle.md.copyWith(
color: AppColor.textSecondary,
),
),
],
),
),
SizedBox(width: 12),
// Voucher Icon
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey[300]!, width: 1),
),
child: Stack(
alignment: Alignment.center,
children: [
Icon(
Icons.local_offer_outlined,
color: AppColor.primary,
size: 24,
),
Positioned(
top: 6,
right: 6,
child: Container(
width: 16,
height: 16,
decoration: BoxDecoration(
color: AppColor.error,
shape: BoxShape.circle,
),
child: Icon(
Icons.percent,
color: Colors.white,
size: 10,
return GestureDetector(
onTap: () => context.router.push(VoucherDetailRoute()),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 12,
offset: Offset(0, 4),
spreadRadius: 0,
),
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 6,
offset: Offset(0, 2),
spreadRadius: 0,
),
],
),
child: ClipPath(
clipper: VoucherClipper(),
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: [
// Main Content
Padding(
padding: EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: AppStyle.lg.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
],
),
),
// Dashed line divider
Container(
height: 1,
margin: EdgeInsets.symmetric(horizontal: 20),
child: CustomPaint(
size: Size(double.infinity, 1),
painter: DashedLinePainter(),
),
),
// Bottom Section
Padding(
padding: EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Berlaku Hingga',
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary,
fontSize: 10,
),
),
SizedBox(height: 2),
Text(
expireDate,
style: TextStyle(
color: AppColor.textPrimary,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
],
SizedBox(height: 4),
Text(
subtitle,
style: AppStyle.md.copyWith(
color: AppColor.textSecondary,
),
),
),
SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Min Transaksi',
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary,
fontSize: 10,
),
),
SizedBox(height: 2),
Text(
minTransaction,
style: AppStyle.md.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w500,
),
),
],
),
),
],
),
),
SizedBox(width: 16),
// Pakai Button
Container(
padding: EdgeInsets.symmetric(
horizontal: 24,
vertical: 10,
),
decoration: BoxDecoration(
color: AppColor.primary,
borderRadius: BorderRadius.circular(20),
),
child: Text(
'Pakai',
style: TextStyle(
color: AppColor.white,
fontSize: 14,
fontWeight: FontWeight.w600,
],
),
),
),
],
SizedBox(width: 12),
// Voucher Icon
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Colors.grey[300]!,
width: 1,
),
),
child: Stack(
alignment: Alignment.center,
children: [
Icon(
Icons.local_offer_outlined,
color: AppColor.primary,
size: 24,
),
Positioned(
top: 6,
right: 6,
child: Container(
width: 16,
height: 16,
decoration: BoxDecoration(
color: AppColor.error,
shape: BoxShape.circle,
),
child: Icon(
Icons.percent,
color: Colors.white,
size: 10,
),
),
),
],
),
),
],
),
),
),
],
// Dashed line divider
Container(
height: 1,
margin: EdgeInsets.symmetric(horizontal: 20),
child: CustomPaint(
size: Size(double.infinity, 1),
painter: DashedLinePainter(),
),
),
// Bottom Section
Padding(
padding: EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Berlaku Hingga',
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary,
fontSize: 10,
),
),
SizedBox(height: 2),
Text(
expireDate,
style: TextStyle(
color: AppColor.textPrimary,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
],
),
),
SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Min Transaksi',
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary,
fontSize: 10,
),
),
SizedBox(height: 2),
Text(
minTransaction,
style: AppStyle.md.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w500,
),
),
],
),
),
],
),
),
SizedBox(width: 16),
// Pakai Button
Container(
padding: EdgeInsets.symmetric(
horizontal: 24,
vertical: 10,
),
decoration: BoxDecoration(
color: AppColor.primary,
borderRadius: BorderRadius.circular(20),
),
child: Text(
'Pakai',
style: TextStyle(
color: AppColor.white,
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
],
),
),
),
),
@@ -0,0 +1,299 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import '../../../../../common/theme/theme.dart';
@RoutePage()
class VoucherDetailPage extends StatelessWidget {
const VoucherDetailPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColor.background,
appBar: AppBar(
title: Text(
'Detail Voucher',
style: AppStyle.xl.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.textPrimary,
),
),
backgroundColor: AppColor.backgroundLight,
elevation: 0,
iconTheme: IconThemeData(color: AppColor.textPrimary),
bottom: PreferredSize(
preferredSize: Size.fromHeight(1),
child: Container(height: 1, color: AppColor.borderLight),
),
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Voucher Card Section
Container(
margin: EdgeInsets.all(16),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: AppColor.primaryGradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppColor.primary.withOpacity(0.3),
offset: Offset(0, 4),
blurRadius: 12,
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Voucher Icon
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: AppColor.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
Icons.local_offer,
color: AppColor.white,
size: 24,
),
),
SizedBox(height: 16),
// Title
Text(
'New User Voucher - Diskon 50% hingga Rp35K',
style: AppStyle.xl.copyWith(
color: AppColor.white,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 8),
// Subtitle
Text(
'Tanpa Min. Belanja',
style: AppStyle.md.copyWith(
color: AppColor.white.withOpacity(0.9),
),
),
SizedBox(height: 20),
// Voucher Details Row
Row(
children: [
Expanded(
child: _buildDetailItem(
icon: Icons.schedule,
label: 'Berlaku hingga',
value: '25 Sep 2025',
),
),
Container(
width: 1,
height: 40,
color: AppColor.white.withOpacity(0.3),
margin: EdgeInsets.symmetric(horizontal: 16),
),
Expanded(
child: _buildDetailItem(
icon: Icons.shopping_cart,
label: 'Min. Transaksi',
value: '-',
),
),
],
),
],
),
),
// Action Buttons
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {
// Copy voucher code functionality
_copyVoucherCode(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.backgroundLight,
foregroundColor: AppColor.primary,
elevation: 0,
padding: EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(color: AppColor.border),
),
),
icon: Icon(Icons.copy, size: 20),
label: Text(
'Salin Kode',
style: AppStyle.md.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.primary,
),
),
),
),
SizedBox(width: 12),
Expanded(
child: ElevatedButton(
onPressed: () {
// Use voucher functionality
_useVoucher(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.primary,
foregroundColor: AppColor.white,
elevation: 0,
padding: EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'Gunakan',
style: AppStyle.md.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.white,
),
),
),
),
],
),
),
SizedBox(height: 24),
// Description Section
_buildSection(
title: 'Deskripsi',
content:
'Dapatkan diskon hingga 50% untuk pembelian pertama Anda! Voucher ini khusus untuk pengguna baru dan berlaku untuk semua kategori produk tanpa minimum pembelian.',
),
SizedBox(height: 16),
// Terms and Conditions Section
_buildSection(
title: 'Syarat dan Ketentuan',
content: _getDefaultTermsAndConditions(),
),
SizedBox(height: 24),
],
),
),
);
}
Widget _buildDetailItem({
required IconData icon,
required String label,
required String value,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, size: 16, color: AppColor.white.withOpacity(0.8)),
SizedBox(width: 4),
Text(
label,
style: AppStyle.xs.copyWith(
color: AppColor.white.withOpacity(0.8),
),
),
],
),
SizedBox(height: 4),
Text(
value,
style: AppStyle.sm.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w600,
),
),
],
);
}
Widget _buildSection({required String title, required String content}) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 16),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColor.backgroundLight,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColor.borderLight),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.bold,
color: AppColor.textPrimary,
),
),
SizedBox(height: 12),
Text(
content,
style: AppStyle.md.copyWith(
color: AppColor.textSecondary,
height: 1.5,
),
),
],
),
);
}
void _copyVoucherCode(BuildContext context) {
// Implementation for copying voucher code
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Kode voucher berhasil disalin!',
style: AppStyle.md.copyWith(color: AppColor.white),
),
backgroundColor: AppColor.success,
behavior: SnackBarBehavior.floating,
margin: EdgeInsets.all(16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
);
}
void _useVoucher(BuildContext context) {
// Implementation for using voucher
// Navigate back to checkout or shopping cart
context.router.back(); // Return true to indicate voucher was selected
}
String _getDefaultTermsAndConditions() {
return '''• Voucher hanya berlaku untuk pengguna baru
• Tidak dapat digabungkan dengan promo lain
• Berlaku untuk semua kategori produk
• Voucher tidak dapat diuangkan
• Voucher akan hangus jika tidak digunakan sebelum tanggal expired
• Satu voucher hanya berlaku untuk satu kali transaksi
• Voucher tidak berlaku untuk produk yang sudah didiskon
• Kebijakan voucher dapat berubah sewaktu-waktu''';
}
}