6.03


//登录功能

Future<void> login(
BuildContext context,
String username,
String password)
async {

Dio dio = Dio();
String checkUrl = "http://192.168.211.14:9090/user/checkCredentials";

Map<String, dynamic> data = {
"user_name": username,
"user_password": password,

};
Response response = await dio.post(checkUrl, data: data);

if (response.statusCode == 200) {
bool isAuthenticated = response.data;

if (isAuthenticated) {
// 显示登录成功对话框
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('登录成功'),
content: Text('欢迎回来!'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop(); // 关闭对话框
},
child: Text('确定'),
),
],
);
},
);
} else {
// 身份验证失败,显示错误消息或采取相应的操作
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('登录失败'),
content: Text('用户名或密码不正确'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop(); // 关闭对话框
},
child: Text('确定'),
),
],
);
},
);
}
}
}

posted @ 2024-06-13 19:07  kxzzow  阅读(10)  评论(0)    收藏  举报