// 加下划线表示私有
Future<String> _getCheck(String username, String password) async {//1
var url = 'http://10.14.4.140:8080/checkApp';
Dio _dio = Dio();
try {
var response = await _dio.post(url, data: {"username": username, "password": password});//2
if (response.statusCode == HttpStatus.ok) {
return response.toString();
}
} catch (e) {
print(e.toString());
}
return "";
}
// 进行调用
onPressed: () {
_getCheck(userController.text, pwdController.text).then((value) {
print(value);
}).catchError((error) {
print('Error: '+error.toString());
});
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text("登入失败"),
);
}
);
},
参考: https://juejin.im/post/5d3eecba6fb9a06b155d97ba
https://zhuanlan.zhihu.com/p/39999205