//登入功能
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('確定'),
),
],
);
},
);
}
}
}