打开天气图不响应颤动

open weather map not response on flutter

资源和站点存在一些问题并出现此错误:

" I/flutter ( 1528): SocketException: 主机查找失败: 'samples.openweathermap.org' (OS 错误: 没有与主机名关联的地址,errno = 7) “

我尝试了几种方法来解决问题,例如:

  1. 打开 GPS
  2. 开启emu或真实设备的网络
  3. 添加使用权限 android:name="android.permission.INTERNET" 以显示
  4. 重启emu和真机

但总是颤动发送 NULL 或错误 exp 纬度和经度也为 Null,但在 emu 中为此解释了 T,对它们进行硬编码...

代码:

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    // TODO: get currentLocation
    super.initState();
    getLocation();
  }

  void getLocation() async {
    Locate location = new Locate();
    await location.getLocate();
    if (location.latitude == null && location.longitude == null) {
      print('------------- Error - null Fuck exp!! -------------');
    }
    print('latitude : ${location.latitude}');
    print('longitude : ${location.longitude}');
    getApi(location);
  }

  void getApi(Locate location) async {
    try {
      http.Response response = await http.get(
          'https://samples.openweathermap.org/data/2.5/weather?lat=35' +
              '&lon=139&appid=fece45cb56143f5b172b004c6f815f46');

      String data = response.body;
      print('------------ Status code : ${response.statusCode}');
      print('------------ Details : $data');
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

另一个文件“定位”:


class Locate {
 double longitude = -18.5333;
 double latitude = 67.4462;

 Future<void> getLocate() async {
   try {
     Position position = await Geolocator.getCurrentPosition(
         desiredAccuracy: LocationAccuracy.low);

     longitude = position.longitude;
     latitude = position.latitude;
   } catch (e, s) {
     print(e);
     print(s);
   }
 }
} ```

它似乎在像 4 这样的低级机器人和其他像几个设备一样它不起作用,如果你有像我一样的问题,请尝试我做的 4 步,如果你再次出错,更换你的真实或 emu 设备

如果 < uses-permission android:name="android.permission.INTERNET"/> 添加到您的 Manifest.xml 文件,但您仍然收到此错误,

然后请放心,当笔记本电脑网络速度较慢并且您正在使用模拟器时会抛出此错误,并再次尝试擦除您的模拟器数据和 运行 应用程序