【问题标题】:How to get images from bing web search apiv7 in my flutter application如何在我的颤振应用程序中从 bing web search apiv7 获取图像
【发布时间】:2019-07-11 20:46:24
【问题描述】:

如何使用 Bing 网络搜索 Apiv7 在我的 Flutter 应用程序中获取照片?

我从官方网站获得了 API 和端点,但我无法获取 JSON 文件以在 item builder child 中调用它。

示例子:new Image.network('${data['value']['webSearchUrl']}'

我不知道该给这个孩子放什么,也不知道把 API 密钥放哪里...

class _PageOneState extends State<PageOne> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new FutureBuilder(
        future: getPics(),
          builder: (context, snapShot){
          Map data = snapShot.data;
          if(snapShot.hasError){
            print(snapShot.error);
            return Text('Failed to get data from server',
              style: TextStyle(color: Colors.red,
              fontSize: 22.0),);
          }else if(snapShot.hasData){
            return new Center(
              child: new ListView.builder(
                itemCount: data.length,
                  itemBuilder: (context, index){
                  return new Column(
                    children: <Widget>[

                      new Container(
                        child: new InkWell(
                          onTap: (){},
                          child: new Image.network(
                            '${data['value']['webSearchUrl']}'
                          ),
                        ),
                      ),
                      new Padding(padding: const EdgeInsets.all(5.0)),
                    ],
                  );
                  }),
            );

          }
          else if(!snapShot.hasData){
            return new Center(child: CircularProgressIndicator(),);
          }
          }
      ),

    );
and below the code -


Future<Map> getPics() async{
  String url =
  'https://api.cognitive.microsoft.com/bing/v7.0/images';
  http.Response response = await http.get(url);
  return json.decode(response.body);
}

【问题讨论】:

    标签: image api dart flutter


    【解决方案1】:

    webSearchUrl 指向一个带有搜索结果的网页,这就是为什么它在Image.network() 中不起作用的原因。尝试将其更改为contentUrl 以获得完整图像;来自第三方网站或 thumbnailUrl 用于 bing 托管的小缩略图网址。

    【讨论】:

      猜你喜欢
      • 2021-05-29
      • 2020-12-28
      • 2020-05-06
      • 2018-05-19
      • 1970-01-01
      • 2020-12-16
      • 2019-08-01
      • 2019-02-01
      • 1970-01-01
      相关资源
      最近更新 更多