feat: sync payment methods
This commit is contained in:
@@ -72,11 +72,13 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
||||
|
||||
// Set a default payment method in case API fails
|
||||
selectedPaymentMethod = PaymentMethod(
|
||||
id: 1,
|
||||
name: 'Cash',
|
||||
description: 'Cash payment',
|
||||
id: "4b1c0d21-c98a-4fc0-a2f9-8d90a0c9d905",
|
||||
organizationId: "3e8b1793-d18b-40c4-a03d-0c6480b630c7",
|
||||
name: "CASH",
|
||||
type: "cash",
|
||||
isActive: true,
|
||||
sortOrder: 1,
|
||||
createdAt: DateTime.tryParse('2025-07-18T03:43:13.857048+07:00'),
|
||||
updatedAt: DateTime.tryParse('2025-07-18T03:43:13.857048+07:00'),
|
||||
);
|
||||
// if (selectTable == null && widget.table != null) {
|
||||
// selectTable = tables.firstWhere(
|
||||
@@ -1041,41 +1043,37 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
||||
8.0),
|
||||
)
|
||||
: null,
|
||||
child: Tooltip(
|
||||
message: method.description ??
|
||||
'No description available',
|
||||
child: isSelected
|
||||
? Button.filled(
|
||||
width: double.infinity,
|
||||
height: 50.0,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
selectedPaymentMethod =
|
||||
method;
|
||||
});
|
||||
},
|
||||
label: method.name
|
||||
?.isNotEmpty ==
|
||||
true
|
||||
? method.name!
|
||||
: 'Unknown',
|
||||
)
|
||||
: Button.outlined(
|
||||
width: double.infinity,
|
||||
height: 50.0,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
selectedPaymentMethod =
|
||||
method;
|
||||
});
|
||||
},
|
||||
label: method.name
|
||||
?.isNotEmpty ==
|
||||
true
|
||||
? method.name!
|
||||
: 'Unknown',
|
||||
),
|
||||
),
|
||||
child: isSelected
|
||||
? Button.filled(
|
||||
width: double.infinity,
|
||||
height: 50.0,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
selectedPaymentMethod =
|
||||
method;
|
||||
});
|
||||
},
|
||||
label: method.name
|
||||
?.isNotEmpty ==
|
||||
true
|
||||
? method.name!
|
||||
: 'Unknown',
|
||||
)
|
||||
: Button.outlined(
|
||||
width: double.infinity,
|
||||
height: 50.0,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
selectedPaymentMethod =
|
||||
method;
|
||||
});
|
||||
},
|
||||
label: method.name
|
||||
?.isNotEmpty ==
|
||||
true
|
||||
? method.name!
|
||||
: 'Unknown',
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
@@ -65,11 +65,13 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
||||
|
||||
// Set a default payment method in case API fails
|
||||
selectedPaymentMethod = PaymentMethod(
|
||||
id: 1,
|
||||
name: 'Cash',
|
||||
description: 'Cash payment',
|
||||
id: "4b1c0d21-c98a-4fc0-a2f9-8d90a0c9d905",
|
||||
organizationId: "3e8b1793-d18b-40c4-a03d-0c6480b630c7",
|
||||
name: "CASH",
|
||||
type: "cash",
|
||||
isActive: true,
|
||||
sortOrder: 1,
|
||||
createdAt: DateTime.tryParse('2025-07-18T03:43:13.857048+07:00'),
|
||||
updatedAt: DateTime.tryParse('2025-07-18T03:43:13.857048+07:00'),
|
||||
);
|
||||
// if (selectTable == null && widget.table != null) {
|
||||
// selectTable = tables.firstWhere(
|
||||
@@ -517,149 +519,149 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
||||
subtitle: 'Silahkan lakukan pembayaran',
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: AppColors.grey,
|
||||
width: 1.0,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: AppColors.grey,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Pelanggan',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Pelanggan',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SpaceHeight(6.0),
|
||||
TextFormField(
|
||||
controller: customerController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Nama Pelanggan',
|
||||
const SpaceHeight(6.0),
|
||||
TextFormField(
|
||||
controller: customerController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Nama Pelanggan',
|
||||
),
|
||||
textCapitalization:
|
||||
TextCapitalization.words,
|
||||
),
|
||||
textCapitalization:
|
||||
TextCapitalization.words,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: AppColors.grey,
|
||||
width: 1.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Metode Pembayaran',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: AppColors.grey,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(12.0),
|
||||
BlocBuilder<PaymentMethodsBloc,
|
||||
PaymentMethodsState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
loading: () => const Center(
|
||||
child: Column(
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Metode Pembayaran',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(12.0),
|
||||
BlocBuilder<PaymentMethodsBloc,
|
||||
PaymentMethodsState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
loading: () => const Center(
|
||||
child: Column(
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 8.0),
|
||||
Text(
|
||||
'Loading payment methods...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
error: (message) => Column(
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 8.0),
|
||||
Text(
|
||||
'Loading payment methods...'),
|
||||
Center(
|
||||
child: Text(
|
||||
'Error loading payment methods: $message'),
|
||||
),
|
||||
const SpaceHeight(16.0),
|
||||
Button.filled(
|
||||
onPressed: () {
|
||||
context
|
||||
.read<
|
||||
PaymentMethodsBloc>()
|
||||
.add(PaymentMethodsEvent
|
||||
.fetchPaymentMethods());
|
||||
},
|
||||
label: 'Retry',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
error: (message) => Column(
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
'Error loading payment methods: $message'),
|
||||
),
|
||||
const SpaceHeight(16.0),
|
||||
Button.filled(
|
||||
onPressed: () {
|
||||
context
|
||||
.read<PaymentMethodsBloc>()
|
||||
.add(PaymentMethodsEvent
|
||||
.fetchPaymentMethods());
|
||||
},
|
||||
label: 'Retry',
|
||||
),
|
||||
],
|
||||
),
|
||||
loaded: (paymentMethods) {
|
||||
log("Loaded ${paymentMethods.length} payment methods");
|
||||
paymentMethods.forEach((method) {
|
||||
log("Payment method: ${method.name} (ID: ${method.id})");
|
||||
});
|
||||
if (paymentMethods.isEmpty) {
|
||||
return Column(
|
||||
children: [
|
||||
const Center(
|
||||
child: Text(
|
||||
'No payment methods available'),
|
||||
),
|
||||
const SpaceHeight(16.0),
|
||||
Button.filled(
|
||||
onPressed: () {
|
||||
context
|
||||
.read<
|
||||
PaymentMethodsBloc>()
|
||||
.add(PaymentMethodsEvent
|
||||
.fetchPaymentMethods());
|
||||
},
|
||||
label: 'Retry',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
loaded: (paymentMethods) {
|
||||
log("Loaded ${paymentMethods.length} payment methods");
|
||||
paymentMethods.forEach((method) {
|
||||
log("Payment method: ${method.name} (ID: ${method.id})");
|
||||
});
|
||||
if (paymentMethods.isEmpty) {
|
||||
return Column(
|
||||
children: [
|
||||
const Center(
|
||||
child: Text(
|
||||
'No payment methods available'),
|
||||
),
|
||||
const SpaceHeight(16.0),
|
||||
Button.filled(
|
||||
onPressed: () {
|
||||
context
|
||||
.read<
|
||||
PaymentMethodsBloc>()
|
||||
.add(PaymentMethodsEvent
|
||||
.fetchPaymentMethods());
|
||||
},
|
||||
label: 'Retry',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Set default selected payment method if none selected or if current selection is not in the list
|
||||
if (selectedPaymentMethod == null ||
|
||||
!paymentMethods.any((method) =>
|
||||
method.id ==
|
||||
selectedPaymentMethod?.id)) {
|
||||
selectedPaymentMethod =
|
||||
paymentMethods.first;
|
||||
}
|
||||
// Set default selected payment method if none selected or if current selection is not in the list
|
||||
if (selectedPaymentMethod == null ||
|
||||
!paymentMethods.any((method) =>
|
||||
method.id ==
|
||||
selectedPaymentMethod
|
||||
?.id)) {
|
||||
selectedPaymentMethod =
|
||||
paymentMethods.first;
|
||||
}
|
||||
|
||||
return Wrap(
|
||||
spacing: 12.0,
|
||||
runSpacing: 8.0,
|
||||
children:
|
||||
paymentMethods.map((method) {
|
||||
final isSelected =
|
||||
selectedPaymentMethod?.id ==
|
||||
method.id;
|
||||
return Tooltip(
|
||||
message: method.description ??
|
||||
'No description available',
|
||||
child: GestureDetector(
|
||||
return Wrap(
|
||||
spacing: 12.0,
|
||||
runSpacing: 8.0,
|
||||
children:
|
||||
paymentMethods.map((method) {
|
||||
final isSelected =
|
||||
selectedPaymentMethod?.id ==
|
||||
method.id;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedPaymentMethod =
|
||||
@@ -699,122 +701,124 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
||||
TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (selectedPaymentMethod?.id == 1)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: AppColors.grey,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Total Bayar',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(8.0),
|
||||
BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||
builder: (context, state) {
|
||||
return TextFormField(
|
||||
controller: totalPriceController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(8.0),
|
||||
),
|
||||
hintText: 'Total harga',
|
||||
),
|
||||
onChanged: (value) {
|
||||
priceValue =
|
||||
value.toIntegerFromText;
|
||||
final int newValue =
|
||||
value.toIntegerFromText;
|
||||
totalPriceController.text =
|
||||
newValue.currencyFormatRp;
|
||||
totalPriceController.selection =
|
||||
TextSelection.fromPosition(
|
||||
TextPosition(
|
||||
offset:
|
||||
totalPriceController
|
||||
.text.length));
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
const SpaceHeight(20.0),
|
||||
BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
children: [
|
||||
Button.outlined(
|
||||
width: 150.0,
|
||||
onPressed: () {
|
||||
totalPriceController.text =
|
||||
uangPas
|
||||
.toString()
|
||||
.currencyFormatRpV2;
|
||||
priceValue = uangPas;
|
||||
},
|
||||
label: 'UANG PAS',
|
||||
),
|
||||
const SpaceWidth(20.0),
|
||||
Button.outlined(
|
||||
width: 150.0,
|
||||
onPressed: () {
|
||||
totalPriceController.text =
|
||||
uangPas2
|
||||
.toString()
|
||||
.currencyFormatRpV2;
|
||||
priceValue = uangPas2;
|
||||
},
|
||||
label: uangPas2
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
),
|
||||
const SpaceWidth(20.0),
|
||||
Button.outlined(
|
||||
width: 150.0,
|
||||
onPressed: () {
|
||||
totalPriceController.text =
|
||||
uangPas3
|
||||
.toString()
|
||||
.currencyFormatRpV2;
|
||||
priceValue = uangPas3;
|
||||
},
|
||||
label: uangPas3
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
if (selectedPaymentMethod?.type == "cash")
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: AppColors.grey,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Total Bayar',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(8.0),
|
||||
BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||
builder: (context, state) {
|
||||
return TextFormField(
|
||||
controller: totalPriceController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(8.0),
|
||||
),
|
||||
hintText: 'Total harga',
|
||||
),
|
||||
onChanged: (value) {
|
||||
priceValue =
|
||||
value.toIntegerFromText;
|
||||
final int newValue =
|
||||
value.toIntegerFromText;
|
||||
totalPriceController.text =
|
||||
newValue.currencyFormatRp;
|
||||
totalPriceController.selection =
|
||||
TextSelection.fromPosition(
|
||||
TextPosition(
|
||||
offset:
|
||||
totalPriceController
|
||||
.text
|
||||
.length));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
const SpaceHeight(20.0),
|
||||
BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
children: [
|
||||
Button.outlined(
|
||||
width: 150.0,
|
||||
onPressed: () {
|
||||
totalPriceController.text =
|
||||
uangPas
|
||||
.toString()
|
||||
.currencyFormatRpV2;
|
||||
priceValue = uangPas;
|
||||
},
|
||||
label: 'UANG PAS',
|
||||
),
|
||||
const SpaceWidth(20.0),
|
||||
Button.outlined(
|
||||
width: 150.0,
|
||||
onPressed: () {
|
||||
totalPriceController.text =
|
||||
uangPas2
|
||||
.toString()
|
||||
.currencyFormatRpV2;
|
||||
priceValue = uangPas2;
|
||||
},
|
||||
label: uangPas2
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
),
|
||||
const SpaceWidth(20.0),
|
||||
Button.outlined(
|
||||
width: 150.0,
|
||||
onPressed: () {
|
||||
totalPriceController.text =
|
||||
uangPas3
|
||||
.toString()
|
||||
.currencyFormatRpV2;
|
||||
priceValue = uangPas3;
|
||||
},
|
||||
label: uangPas3
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
|
||||
Reference in New Issue
Block a user