我是颤振新手,我正在尝试在屏幕上显示服务器的响应。我从服务器获取订单历史记录并尝试将其显示在历史记录屏幕上,你该怎么做?
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");
});
}
}
Run Code Online (Sandbox Code Playgroud)
我没有向服务器请求的经验,所以我不知道如何在除“打印”之外的任何地方显示它
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),
),
],
)
],
),
);
}
} …Run Code Online (Sandbox Code Playgroud) 我正在从服务器 API 获取数据,数据已成功从服务器获取,但问题是当数据提供给 Listview 时无法显示。如何在 flutter/dart 中显示 Listview 上的数据?
以下是从服务器 API 获取数据的代码
List<String> jobTitles = [];
List officeNames = [ ];
List officeLocations = [ ];
List jobTypes = [ ];
Future getJobsData() async {
var response = await http
.get(Uri.https('hospitality92.com', 'api/jobsbycategory/All'));
Map<String, dynamic> map = json.decode(response.body);
List<dynamic> jobData = map["jobs"];
if (jobTitles.length != 0) {
officeNames.clear();
jobTitles.clear();
officeLocations.clear();
jobTypes.clear();
}
for (var i = 0; i < jobData.length; i++) {
jobTitles.add(jobData[i]["title"]);
officeNames.add(jobData[i]["company_name"]);
officeLocations.add(jobData[i]["company_name"]);
jobTypes.add(jobData[i]["type"]);
}
/* print(jobTitles);
print(officeNames);
print(officeLocations); …Run Code Online (Sandbox Code Playgroud)