我可以在将来的构建器上使用多种方法吗

我可以在将来的构建器上使用多种方法吗

本文介绍了我可以在将来的构建器上使用多种方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

     @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(),+(另一个方法),就像我想要的那样.用values [index] ["name"]替换values [index] ["ticket_type_id"],该名称是我通过_getTicketType()方法获得的新索引响应.预先谢谢你!

Hi everyone, I have a question.As I am sending multiple API request and building dynamically a card with the response that I get in return, I was wondering if I could include more that one method within future: _getAllTickets(), + (another method), as I would like to substitute values[index]["ticket_type_id"] with values[index]["name"], which name is a new index response that I have got through the method _getTicketType().Thank you in advance!

推荐答案

您可以使用 Future.wait(Future [])返回期货列表.

You can use Future.wait(Future[]) to return a list of futures.

Future<String> foo;
Future<int> bar;
FutureBuilder(
  future: Future.wait([bar, foo]),
  builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
    snapshot.data[0]; //bar
    snapshot.data[1]; //foo
  },
);

这篇关于我可以在将来的构建器上使用多种方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:57