diff --git a/lib/features/contact/presentation/screens/contact_screen.dart b/lib/features/contact/presentation/screens/contact_screen.dart index 2393142..d2036c6 100644 --- a/lib/features/contact/presentation/screens/contact_screen.dart +++ b/lib/features/contact/presentation/screens/contact_screen.dart @@ -627,9 +627,10 @@ class _ContactScreenState extends State { } // -- Send Message -- - void _sendMessage() { + Future _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 { 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 { 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, + ), + ); + } } }