我是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");
});
}
}
我没有向服务器发出请求的经验,因此除了 "print" 之外,我不知道如何在任何其他地方显示它。
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”只是一个列表视图,我需要在这里粘贴我的响应代码吗?当我切换到“历史记录屏幕”时,我想获取所有订单历史记录。我会非常感激提供代码示例。