如何将两个功能添加到单个按钮?我有一个向服务器发送请求的按钮,我想在发送请求后添加一个对话框......我试过这个:
onPressed: () {
_makePostRequest();
showAlertDialog(context);
},
但仍然无法正常工作...
邮政编码:
_makePostRequest() async {
final url = Uri.parse('http://127.0.0.1/API');
final headers = {"Content-type": "application/json"};
final json = '{"id": "1", "status": "1"}';
final response = await post(url, headers: headers, body: json);
final statusCode = response.statusCode;
final body = response.body;
}
显示对话框代码:
void showAlertDialog(BuildContext context) {
Widget okButton = TextButton(
child: Text("OK"),
onPressed: () {},
);
AlertDialog alert = AlertDialog(
title: Text("PMZ Label Print"),
content: Text("Label is printing..."),
actions: [
okButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}