无法将参数类型“String”分配给 uri.encodeFull() 中的参数类型“Uri”

Abd*_*man 1 url uri http dart flutter

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));
  }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试 uri.encodeFull(url) 时,错误位于最后 3 行,它给了我上面所述的错误,但是当我将 url 的类型转换为 Uri 时,它一直给我同样的错误。我什至还尝试了 uri.parse() 函数,如评论中所示,我不知道这里的问题是什么,如果有人知道请随时回答。

iDe*_*ode 5

正如@jamesdlin先生提到的,你需要这样的东西:

Future<String> getWeatherForecast({String cityName}) async {
  final url = 'http://api.openweathermap.org/...';
  final response = await get(Uri.parse(Uri.encodeFull(url)));
  //...
}
Run Code Online (Sandbox Code Playgroud)