简体   繁体   English

如何从 flutter 中的 API 响应中获取标头

[英]How can I get the headers from the API response in flutter

So if the response is {['myHeader': 'myData']}.所以如果响应是 {['myHeader': 'myData']}。

how can I get the 'myHeader'.我怎样才能得到'myHeader'。

   FutureBuilder(
                          future: api_response,
    
                          builder: (context, snapshot){
                            return Text(snapshot.data[0]['myHeader']);
                          },
)

This is the code that I've been using to get the 'myData'.这是我用来获取“myData”的代码。

Thanks in advance提前致谢

Please try testing below code.请尝试测试下面的代码。 You need to return Widget when snapshot has a data.当快照有数据时,您需要返回 Widget。

   FutureBuilder(
                          future: api_response,
    
                          builder: (context, snapshot){
                             if (snapshot.hasData) {
                                 return Text(snapshot.data[0]['myHeader']);
                             }
                          },
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM