feat: Implement actual API call for sending contact messages with Dio, including phone number, and add error handling.

This commit is contained in:
pradeepkumar
2026-03-20 12:41:57 +05:30
parent 744787bae2
commit f3e48925b2

View File

@@ -627,9 +627,10 @@ class _ContactScreenState extends State<ContactScreen> {
}
// -- Send Message --
void _sendMessage() {
Future<void> _sendMessage() async {
final name = _nameController.text.trim();
final email = _emailController.text.trim();
final phone = _phoneController.text.trim();
final message = _messageController.text.trim();
if (name.isEmpty || email.isEmpty || message.isEmpty) {
@@ -644,8 +645,15 @@ class _ContactScreenState extends State<ContactScreen> {
setState(() => _isSending = true);
// Simulate sending — replace with actual API call
Future.delayed(const Duration(seconds: 2), () {
try {
final dio = ApiClient.instance.dio;
await dio.post('/contact', data: {
'name': name,
'email': email,
if (phone.isNotEmpty) 'phone': phone,
'message': message,
});
if (!mounted) return;
setState(() => _isSending = false);
_nameController.clear();
@@ -658,7 +666,16 @@ class _ContactScreenState extends State<ContactScreen> {
backgroundColor: Color(0xFF638559),
),
);
});
} catch (e) {
if (!mounted) return;
setState(() => _isSending = false);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Failed to send message. Please try again.'),
backgroundColor: Colors.red,
),
);
}
}
}