Files
worker/lib/features/cart/presentation/widgets/checkout_submit_button.dart
Phuoc Nguyen 988216b151 payment page
2025-11-03 16:16:15 +07:00

143 lines
4.3 KiB
Dart

/// Checkout Submit Button Widget
///
/// Place order or send negotiation request button.
library;
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:worker/core/constants/ui_constants.dart';
import 'package:worker/core/router/app_router.dart';
import 'package:worker/core/theme/colors.dart';
/// Checkout Submit Button
///
/// Button that changes based on negotiation checkbox state.
class CheckoutSubmitButton extends StatelessWidget {
final GlobalKey<FormState> formKey;
final bool needsNegotiation;
final bool needsInvoice;
final String name;
final String phone;
final String address;
final String? province;
final String? ward;
final String paymentMethod;
final String companyName;
final String taxId;
final double total;
const CheckoutSubmitButton({
super.key,
required this.formKey,
required this.needsNegotiation,
required this.needsInvoice,
required this.name,
required this.phone,
required this.address,
required this.province,
required this.ward,
required this.paymentMethod,
required this.companyName,
required this.taxId,
required this.total,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
child: Column(
children: [
// Terms Agreement Text
const Text(
'Bằng việc đặt hàng, bạn đồng ý với các điều khoản và điều kiện của chúng tôi',
style: TextStyle(fontSize: 12, color: AppColors.grey500),
textAlign: TextAlign.center,
),
const SizedBox(height: AppSpacing.md),
// Place Order / Send Negotiation Button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
if (formKey.currentState?.validate() ?? false) {
_handlePlaceOrder(context);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: needsNegotiation
? AppColors.warning
: AppColors.primaryBlue,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.button),
),
),
child: Text(
needsNegotiation ? 'Gửi yêu cầu đàm phán' : 'Đặt hàng',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
);
}
/// Handle place order
void _handlePlaceOrder(BuildContext context) {
// TODO: Implement actual order placement with backend
if (needsNegotiation) {
// Show negotiation request sent message
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Yêu cầu đàm phán giá đã được gửi!'),
backgroundColor: AppColors.success,
duration: Duration(seconds: 2),
),
);
// Navigate back after a short delay
Future.delayed(const Duration(milliseconds: 500), () {
if (context.mounted) {
context.pop();
}
});
} else {
// Generate order ID (mock - replace with actual from backend)
final orderId = 'DH${DateTime.now().millisecondsSinceEpoch.toString().substring(7)}';
// Show order success message
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Đặt hàng thành công! Chuyển đến thanh toán...'),
backgroundColor: AppColors.success,
duration: Duration(seconds: 1),
),
);
// Navigate to payment QR page after a short delay
Future.delayed(const Duration(milliseconds: 500), () {
if (context.mounted) {
context.pushNamed(
RouteNames.paymentQr,
queryParameters: {
'orderId': orderId,
'amount': total.toString(),
},
);
}
});
}
}
}