createContact function
Implementation
Future<Contact> createContact(
// String q1,
// String q2,
// String q3,
// String q4,
String selectDepartment,
String name,
String email,
String subject,
int contactNumber,
String message,
) async {
HttpOverrides.global = new MyHttpOverrides();
final response = await http.post(
// Uri.parse('https://172.30.1.33:45455/api/ContactModels'),
Uri.parse('https://192.168.1.106:45455/api/ContactModels'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
// 'q1': q1,
// 'q2': q2,
// 'q3': q3,
// 'q4': q4,
'selectDepartment': selectDepartment,
'name': name,
'email': email,
'subject': subject,
'contactNumber': contactNumber.toString(),
'message': message,
}),
);
if (response.statusCode == 201) {
// If the server did return a 201 CREATED response,
// then parse the JSON.
return Contact.fromJson(jsonDecode(response.body));
} else {
// If the server did not return a 201 CREATED response,
// then throw an exception.
throw Exception('Failed to create user.');
}
}