class Tickets extends StatefulWidget {
int groupid;
int event_id;
List returnTickets = [];
Map<String, dynamic> hey;
Tickets([this.groupid,this.event_id,this.hey,this.returnTickets]);
@override
_TicketsState createState() => new _TicketsState();
}
class _TicketsState extends State<Tickets> {
List returnTickets = [];
List ticketType = [];
Map<String, dynamic> hey;
int i = 0;
@override
void initState() {
super.initState();
// _getTicketType();
}
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
widget.groupid;
widget.event_id;
var futureBuilder = new FutureBuilder(
future: Future.wait([hey, returnTickets]).then(
(response) => new _TicketsState(hey: response[0], returnTickets: response[1]),
),
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);
}
},
);
大家好,我正在尝试实现Future.wait函数,因此我希望在构建小部件中使用的不仅仅是一种方法,但是当我尝试这样做时,我得到这个长错误,请问有什么帮助吗? ? 非常感谢你提前感谢。
答案 0 :(得分:0)
不建议在Dart2(List
)中使用所谓的“原始”类型。在这种特殊情况下,Future.wait
需要List<Future>
,但您已(隐式)在此处创建了List<Object>
:
List returnTickets = [];
这适用于Dart1,因为List<dynamic>
可能假装为List<T>
。
尝试写作:
List<Future> returnTickets = [];
或者,更好的是:
final returnTickets = <Future>[];