【发布时间】:2021-06-26 07:50:50
【问题描述】:
import 'package:weathertempo/model/forecastModel.dart';
import 'package:weathertempo/util/forecast_util.dart';
import 'package:http/http.dart';
class Network {
Future<WeatherForecastModel> getWeatherForecast({String cityName}) async {
String url =
"http://api.openweathermap.org/data/2.5/forecast/daily?q=" +
cityName +
'&APPID=' +
Util.appId +
'&units=metric';
// Uri.parse(finalUrl);
final response = await get(Uri.encodeFull(url));
}
}
当我尝试 uri.encodeFull(url) 时,错误出现在最后一行的第三行,它给了我上述错误,但是当我将 url 的类型转换为 Uri 时,它一直给我同样的错误。我什至还尝试了 uri.parse() 函数,如评论中所示我不知道这里有什么问题,如果有人知道,请随时回答。
【问题讨论】:
-
Uri.encodeFull将String作为参数并返回String。http.get现在需要Uri参数(请参阅 stackoverflow.com/q/66473263)。您需要致电get(Uri.parse(url))。 -
@jamesdlin 好的,让我试试