标签:String,Text,6.04,BuildContext,user,context,text From: https://www.cnblogs.com/kongxiangzeng/p/18246585
// 发帖功能
Future<void> insertColumn(
BuildContext context,
String username,
String text)
async {
Dio dio = Dio();
String insertUrl = "http://192.168.211.14:9090/user/user_column";
Map<String, dynamic> data = {
"user_name": username,
"date": DateTime.now().toIso8601String(), // 将 DateTime 转换为 ISO 8601 格式的字符串
"text": text,
"number": 0, // 默认值为0
};
Response response = await dio.post(insertUrl, data: data);
if (response.statusCode == 200) {
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('确定'),
),
],
);
},
);
}
}