When I use try and catch to use the API insert operation and the operation inserted successfully, but unfortunately the toast message doesn't print "signed up successfully", it prints this:
"Error: ClientException: XMLHttpRequest error., uri="http://localhost/dashboard/help_me/signup.php"
Future<void> SignupClient() async {
if (name.text!= "" || phone.text!= "") {
try {
var res = await http.post(
Uri.parse(ApisConnect.signupApi),
body:
{
"name": name.text,
"phone": phone.text,
}
);
var response = jsonDecode(res.body);
if (response["success"] == true) {
Fluttertoast.showToast(msg: 'signed up successfully');
} else if (response["success"] == false) {
Fluttertoast.showToast(msg: 'try again');
}
} catch (e) {
Fluttertoast.showToast(msg: 'Error $e');
}
}
}
I tried to remove try and catch or change this.