@override
Widget build(BuildContext context) {
widget.groupid;
widget.event_id;
var futureBuilder = new FutureBuilder(
future: _getAllTickets(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
print(snapshot.connectionState);
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return new Text('...');
default:
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
else
return createListTickets(context, snapshot);
}
},
);
return new Scaffold(
body: futureBuilder,
);
}
Widget createListTickets(BuildContext context, AsyncSnapshot snapshot) {
List values = snapshot.data;
child: new Card(
child:
new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
new Text(
values[index]["ticket_type_id"].toString(), style:
const TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w600,
fontSize: 25.0)),
}
_getAllTickets() async {
final response = await http.get(
"https...}"
, headers: {
HttpHeaders.AUTHORIZATION: access_token
});
returnTickets = json.decode(response.body);
return returnTickets;
}
_getTicketType() async {
for (i = 0; i < (returnTickets?.length ?? 0); i++) {
/*print("https....);*/
final responseType = await http.get(
"https...}"
, headers: {
HttpHeaders.AUTHORIZATION: access_token
});
Map<String, dynamic> hey = json.decode(responseType.body);
}
大家好,我有一个问题。 当我发送多个API请求并动态构建具有我得到的响应的卡时,我想知道我是否可以在将来包含更多的那个方法:_getAllTickets(),+(另一种方法),因为我想使用值[index] [&#34; name&#34;]替换值[index] [&#34; ticket_type_id&#34;],该名称是我通过方法_getTicketType()获得的新索引响应。 提前谢谢!
答案 0 :(得分:4)
您可以使用Future.wait(Future[])
将期货列表合并为一个。
class Merged {
final String foo;
final String bar;
Merged({this.foo, this.bar});
}
Future<String> foo;
Future<int> bar;
new FutureBuilder(
future: Future.wait([bar, foo]).then(
(response) => new Merged(foo: response[0], bar: response[1]),
),
builder: (context, AsyncSnapshot<Merged> snapshot) {
},
);