【发布时间】:2021-10-02 10:40:02
【问题描述】:
我是 Flutter 的新手,我正在尝试在我的屏幕上显示来自服务器的响应。我从服务器订单历史记录中获取并尝试在历史记录屏幕上显示它,你该怎么做?
void getAllHistory() async {
http
.post(
Uri.parse(
'https://myurlblahblah'),
body: "{\"token\":\"admin_token\"}",
headers: headers)
.then((response) {
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}).catchError((error) {
print("Error: $error");
});
}
}
我没有向服务器请求的经验,所以除了“打印”之外,我不知道如何在任何地方显示它
class HistoryScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(),
body: BodyLayout(),
);
}
AppBar buildAppBar() {
return AppBar(
automaticallyImplyLeading: false,
title: Row(
children: [
BackButton(),
SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Orders history",
style: TextStyle(fontSize: 16),
),
],
)
],
),
);
}
}
PS“BodyLayout”只是一个列表视图,我需要在此处粘贴我的响应代码吗?我想在切换到“历史屏幕”时获取所有订单历史记录,我非常感谢代码示例
【问题讨论】:
-
在示例中他们使用了“required”,当我尝试使用它时,它说“required 不是一种类型”也许随着更新而发生了变化,我知道这里有什么解决方案
-
改用@required
-
哇哦,非常感谢