Flutter 和 Weather API:未处理的异常“主机查找失败”

问题描述 投票:0回答:0
import 'dart:convert';

import 'package:http/http.dart' as http;
class WeatherServices
# {
void getWeather({required String cityName}) async
#   {
String baseUrl = "http://api.weatherapi.com/v1";
String apiKey = "my_api";
Uri url = Uri.parse("$baseUrl/forecast.json?key=$apiKey&q=$cityName&days=3");
http.Response response = await http.get(url);
Map<String , dynamic> data = jsonDecode(response.body);

print(data);
  }
 }

[错误:flutter/runtime/dart_vm_initializer.cc(41)] 未处理的异常:主机查找失败:'api.weatherapi.com'

json flutter api http
© www.soinside.com 2019 - 2024. All rights reserved.