【发布时间】:2021-06-10 23:11:37
【问题描述】:
我正在使用 Flutter,我正在尝试将我的应用程序连接到数据库,但是我可以连接,因为在这句话中(在 url 中)总是出现该错误:
var response = await http.post(url, body: json.encode(data));
,有谁知道问题出在哪里?代码如下:
class LoginUserState extends State {
// For CircularProgressIndicator.
bool visible = false ;
// Getting value from TextField widget.
final emailController = TextEditingController();
final passwordController = TextEditingController();
Future userLogin() async{
// Showing CircularProgressIndicator.
setState(() {
visible = true ;
});
// Getting value from Controller
String email = emailController.text;
String password = passwordController.text;
// SERVER LOGIN API URL
var url = 'https://fluer-examples.com/login_user.php';
// Store all data with Param Name.
var data = {'email': email, 'password' : password};
// Starting Web API Call.
var response = await http.post(url, body: json.encode(data));
// Getting Server response into variable.
var message = jsonDecode(response.body);
// If the Response Message is Matched.
if(message == 'Login Matched')
{
// Hiding the CircularProgressIndicator.
setState(() {
visible = false;
});
// Navigate to Profile Screen & Sending Email to Next Screen.
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProfileScreen(email : emailController.text))
);
}else{
// If Email or Password did not Matched.
// Hiding the CircularProgressIndicator.
setState(() {
visible = false;
});
// Showing Alert Dialog with Response JSON Message.
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text(message),
actions: <Widget>[
FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);}
}
【问题讨论】:
-
那是什么错误?那也很有帮助!