【问题标题】:getting http request from pexel api从 pexel api 获取 http 请求
【发布时间】:2021-05-28 11:50:37
【问题描述】:

我正在创建一个壁纸应用程序,我在其中通过 pexel api 获取壁纸。但是当我制作一个响应变量并赋予它 http.get(url) 的值时;在这里我粘贴了 api 中给出的精选壁纸的链接,但它给出了这样的错误:参数类型“字符串”不能分配给参数类型“Uri”。谁能告诉我如何解决。我正在遵循的教程是他直接将链接粘贴为字符串,并且没有给他任何错误。 这是该代码的示例 :

import 'package:http/http.dart' as http;

getTrendingWallpaper() {
    var trendingUrl = "https://api.pexels.com/v1/curated?per_page=1";
    var response = http.get(trendingUrl); // this is giveing this error :  The argument type 'String' can't be assigned to the parameter type 'Uri'
  }

【问题讨论】:

    标签: api flutter http get wallpaper


    【解决方案1】:

    你应该使用

    var trendingUrl = Uri.parse("https://api.pexels.com/v1/curated?per_page=1");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-20
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      相关资源
      最近更新 更多