Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Dart Uri Api-请求通过将HTML代码指定给问号来更改链接_Flutter_Dart_Flutter Layout_Dart Pub - Fatal编程技术网

Flutter Dart Uri Api-请求通过将HTML代码指定给问号来更改链接

Flutter Dart Uri Api-请求通过将HTML代码指定给问号来更改链接,flutter,dart,flutter-layout,dart-pub,Flutter,Dart,Flutter Layout,Dart Pub,我想从API获取一些数据,链接包含问号,使用Uri的请求更改了链接,因此无法访问我的链接 Uri url = Uri.https('api.aladhan.com', 'v1/calendar?latitude=45.53157194849857&longitude=9.13990990079155&method=2&month=5&year=2021'); Future<MonthPrayers> fetchAlbum() async {

我想从API获取一些数据,链接包含问号,使用Uri的请求更改了链接,因此无法访问我的链接

Uri url = Uri.https('api.aladhan.com',
    'v1/calendar?latitude=45.53157194849857&longitude=9.13990990079155&method=2&month=5&year=2021');
Future<MonthPrayers> fetchAlbum() async {
  final response = await http.get(url);

  if (response.statusCode == 200) {
    return MonthPrayers.fromJson(jsonDecode(response.body));
  } else {
    print("Uri : " + url.toString());
    throw Exception('Failed to load album');
  }
}
uriurl=Uri.https('api.aladhan.com',
‘v1/日历?纬度=45.53157194849857,经度=9.13990990079155,方法=2,月=5,年=2021’;
Future fetchAlbum()异步{
最终响应=等待http.get(url);
如果(response.statusCode==200){
返回monthparyers.fromJson(jsonDecode(response.body));
}否则{
打印(“Uri:+url.toString());
抛出异常(“加载相册失败”);
}
}
打印结果:

Uri:https://api.aladhan.com/v1/calendar%3Flatitude=45.53157194849857&longitude=9.13990990079155&method=2&month=5&year=2021

%3F

因此请求无法加载数据

构建查询映射

 Map<String, dynamic> params = {
     'latitude': 45.53157194849857,
     'longitude': 9.13990990079155,
     'method': 2,
     'month': 5,
     'year': 2021,
    };

var url = Uri.https('api.aladhan.com', 'v1/calendar', params);
//..
Map参数={
“纬度”:45.53157194849857,
“经度”:9.13990990079155,
"方法":2,,
“月”:5,
“年份”:2021年,
};
var url=Uri.https('api.aladhan.com','v1/calendar',params);
//..
只需使用而不是
Uri.https
。它更简单,更不容易出错

uriurl=Uri.parse('https://api.aladhan.com/v1/calendar?latitude=45.53157194849857&longitude=9.13990990079155&method=2&month=5&year=2021');

它可以工作,非常感谢,但是它仍然给出了一个错误,下面的解决方案可以工作,再次感谢