feat: Implement actual API call for sending contact messages with Dio, including phone number, and add error handling.
This commit is contained in:
@@ -627,9 +627,10 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -- Send Message --
|
// -- Send Message --
|
||||||
void _sendMessage() {
|
Future<void> _sendMessage() async {
|
||||||
final name = _nameController.text.trim();
|
final name = _nameController.text.trim();
|
||||||
final email = _emailController.text.trim();
|
final email = _emailController.text.trim();
|
||||||
|
final phone = _phoneController.text.trim();
|
||||||
final message = _messageController.text.trim();
|
final message = _messageController.text.trim();
|
||||||
|
|
||||||
if (name.isEmpty || email.isEmpty || message.isEmpty) {
|
if (name.isEmpty || email.isEmpty || message.isEmpty) {
|
||||||
@@ -644,8 +645,15 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
|
|
||||||
setState(() => _isSending = true);
|
setState(() => _isSending = true);
|
||||||
|
|
||||||
// Simulate sending — replace with actual API call
|
try {
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
final dio = ApiClient.instance.dio;
|
||||||
|
await dio.post('/contact', data: {
|
||||||
|
'name': name,
|
||||||
|
'email': email,
|
||||||
|
if (phone.isNotEmpty) 'phone': phone,
|
||||||
|
'message': message,
|
||||||
|
});
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _isSending = false);
|
setState(() => _isSending = false);
|
||||||
_nameController.clear();
|
_nameController.clear();
|
||||||
@@ -658,7 +666,16 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
backgroundColor: Color(0xFF638559),
|
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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user