update
This commit is contained in:
@@ -111,8 +111,9 @@ class OrderDetailPage extends ConsumerWidget {
|
||||
_buildPaymentHistoryCard(context, orderDetail),
|
||||
],
|
||||
|
||||
// Cancel Order Button (only show for "Chờ phê duyệt" status)
|
||||
if (orderDetail.order.status == 'Chờ phê duyệt') ...[
|
||||
// Cancel Order Button
|
||||
// Use API flag to determine if cancellation is allowed
|
||||
if (orderDetail.order.isAllowCancel) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildCancelOrderButton(context, ref, orderDetail),
|
||||
],
|
||||
@@ -405,90 +406,98 @@ class OrderDetailPage extends ConsumerWidget {
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// Navigate to address selection and wait for result
|
||||
final result = await context.push<Address>(
|
||||
'/account/addresses',
|
||||
extra: {
|
||||
'selectMode': true,
|
||||
'currentAddress': shippingAddress,
|
||||
},
|
||||
);
|
||||
|
||||
// If user selected an address, update the order
|
||||
if (result != null && context.mounted) {
|
||||
// Show loading indicator
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đang cập nhật địa chỉ...'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
|
||||
// Update shipping address (keep billing address the same)
|
||||
await ref
|
||||
.read(updateOrderAddressProvider.notifier)
|
||||
.updateAddress(
|
||||
orderId: orderId,
|
||||
shippingAddressName: result.name,
|
||||
customerAddress: orderDetail.billingAddress.name,
|
||||
Builder(
|
||||
builder: (context) {
|
||||
// Use API flag to determine if editing is allowed
|
||||
if (orderDetail.shippingAddress.isAllowEdit) {
|
||||
return TextButton(
|
||||
onPressed: () async {
|
||||
// Navigate to address selection and wait for result
|
||||
final result = await context.push<Address>(
|
||||
'/account/addresses',
|
||||
extra: {
|
||||
'selectMode': true,
|
||||
'currentAddress': shippingAddress,
|
||||
},
|
||||
);
|
||||
|
||||
// Check if update was successful
|
||||
final updateState =
|
||||
ref.read(updateOrderAddressProvider)
|
||||
..when(
|
||||
data: (_) {
|
||||
// Refresh order detail to show updated address
|
||||
ref.invalidate(orderDetailProvider(orderId));
|
||||
// If user selected an address, update the order
|
||||
if (result != null && context.mounted) {
|
||||
// Show loading indicator
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đang cập nhật địa chỉ...'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
|
||||
// Show success message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Cập nhật địa chỉ giao hàng thành công',
|
||||
),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
// Update shipping address (keep billing address the same)
|
||||
await ref
|
||||
.read(updateOrderAddressProvider.notifier)
|
||||
.updateAddress(
|
||||
orderId: orderId,
|
||||
shippingAddressName: result.name,
|
||||
customerAddress: orderDetail.billingAddress.name,
|
||||
);
|
||||
|
||||
// Check if update was successful
|
||||
final updateState =
|
||||
ref.read(updateOrderAddressProvider)
|
||||
..when(
|
||||
data: (_) {
|
||||
// Refresh order detail to show updated address
|
||||
ref.invalidate(orderDetailProvider(orderId));
|
||||
|
||||
// Show success message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Cập nhật địa chỉ giao hàng thành công',
|
||||
),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (error, _) {
|
||||
// Show error message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Lỗi: ${error.toString()}',
|
||||
),
|
||||
backgroundColor: AppColors.danger,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (error, _) {
|
||||
// Show error message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Lỗi: ${error.toString()}',
|
||||
),
|
||||
backgroundColor: AppColors.danger,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
minimumSize: Size.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
side: const BorderSide(color: AppColors.grey100),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cập nhật',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primaryBlue,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
minimumSize: Size.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
side: const BorderSide(color: AppColors.grey100),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cập nhật',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primaryBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -621,91 +630,100 @@ class OrderDetailPage extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// Navigate to address selection and wait for result
|
||||
final result = await context.push<Address>(
|
||||
'/account/addresses',
|
||||
extra: {
|
||||
'selectMode': true,
|
||||
'currentAddress': billingAddress,
|
||||
},
|
||||
);
|
||||
|
||||
// If user selected an address, update the order
|
||||
if (result != null && context.mounted) {
|
||||
// Show loading indicator
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đang cập nhật địa chỉ...'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
|
||||
// Update billing address (keep shipping address the same)
|
||||
await ref
|
||||
.read(updateOrderAddressProvider.notifier)
|
||||
.updateAddress(
|
||||
orderId: orderId,
|
||||
shippingAddressName: orderDetail.shippingAddress.name,
|
||||
customerAddress: result.name,
|
||||
Builder(
|
||||
builder: (context) {
|
||||
// Use API flag to determine if editing is allowed
|
||||
if (orderDetail.billingAddress.isAllowEdit) {
|
||||
return TextButton(
|
||||
onPressed: () async {
|
||||
// Navigate to address selection and wait for result
|
||||
final result = await context.push<Address>(
|
||||
'/account/addresses',
|
||||
extra: {
|
||||
'selectMode': true,
|
||||
'currentAddress': billingAddress,
|
||||
},
|
||||
);
|
||||
|
||||
// Check if update was successful
|
||||
final updateState =
|
||||
ref.read(updateOrderAddressProvider)
|
||||
..when(
|
||||
data: (_) {
|
||||
// Refresh order detail to show updated address
|
||||
ref.invalidate(orderDetailProvider(orderId));
|
||||
// If user selected an address, update the order
|
||||
if (result != null && context.mounted) {
|
||||
// Show loading indicator
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đang cập nhật địa chỉ...'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
|
||||
// Show success message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Cập nhật địa chỉ hóa đơn thành công',
|
||||
),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
// Update billing address (keep shipping address the same)
|
||||
await ref
|
||||
.read(updateOrderAddressProvider.notifier)
|
||||
.updateAddress(
|
||||
orderId: orderId,
|
||||
shippingAddressName: orderDetail.shippingAddress.name,
|
||||
customerAddress: result.name,
|
||||
);
|
||||
|
||||
// Check if update was successful
|
||||
final updateState =
|
||||
ref.read(updateOrderAddressProvider)
|
||||
..when(
|
||||
data: (_) {
|
||||
// Refresh order detail to show updated address
|
||||
ref.invalidate(orderDetailProvider(orderId));
|
||||
|
||||
// Show success message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Cập nhật địa chỉ hóa đơn thành công',
|
||||
),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (error, _) {
|
||||
// Show error message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Lỗi: ${error.toString()}',
|
||||
),
|
||||
backgroundColor: AppColors.danger,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (error, _) {
|
||||
// Show error message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Lỗi: ${error.toString()}',
|
||||
),
|
||||
backgroundColor: AppColors.danger,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
minimumSize: Size.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
side: const BorderSide(color: AppColors.grey100),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cập nhật',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primaryBlue,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
minimumSize: Size.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
side: const BorderSide(color: AppColors.grey100),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cập nhật',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primaryBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user