6.04


// 发帖功能
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('确定'),
),
],
);
},
);
}
}

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