validateUserEmail() async
{
try
{
var res = await http.post(
Uri.parse(API.validateEmail),
body: {
'user_email': emailController.text.trim(),
},
);
if(res.statusCode == 200)//The HTTP 200 OK success status response code
// indicates that the request has succeeded.
{
var resBodyOfValidateEmail = jsonDecode(res.body);
if(resBodyOfValidateEmail['emailFound'] == true)
{
Fluttertoast.showToast(msg: "Email already in use.");
}
else
{
//register and save new user to database
registerAndSaveUserRecord();
}
}
}
catch(e)
{
print(e.toString());
Fluttertoast.showToast(msg: e.toString());
}
}
registerAndSaveUserRecord() async
{
User userModel = User(
1,
nameController.text.trim(),
emailController.text.trim(),
passwordController.text.trim(),
);
try
{
var res = await http.post(
Uri.parse(API.signUp),
body: userModel.toJson(),
);
if(res.statusCode == 200)
{
var resBodyOfSignUp = jsonDecode(res.body);
if(resBodyOfSignUp['success'] == true)
{
Fluttertoast.showToast(msg: "You have signup successfully.");
}
else
{
Fluttertoast.showToast(msg: "Error try again");
}
}
}
catch(e)
{
print(e.toString());
Fluttertoast.showToast(msg: e.toString());
}
}
伙计们,我一直得到这个错误在Android工作室当我试图注册一个新用户到我的扑动应用程序
图片显示了我认为问题所在的区域
我试着仔细检查代码,看看是否有任何拼写错误或代码中断。
可能是什么问题?
似乎你正在尝试解码json,但API正在发送HTML而不是json字符串,所以这就是为什么它解码失败。我建议在尝试解码主体之前检查api发送给您的内容。