Http requests don't return anything in Flutter, and no errors are thrown

Viewed 544

This is really confusing me, using the simple default http library. Http requests never return and don't throw any errors.

Heres the doctor log:

[√] Flutter (Channel master, 1.19.0-2.0.pre.34, on Microsoft Windows [Version 10.0.18362.836], locale en-US)
    • Flutter version 1.19.0-2.0.pre.34 at E:\FlutterSDK
    • Framework revision 610dc170d9 (3 days ago), 2020-05-14 00:37:02 +0800
    • Engine revision b59e3e9c39
    • Dart version 2.9.0 (build 2.9.0-8.0.dev 2bf3259005)


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at E:\AndroidSDK
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = E:\AndroidSDK
    • Java binary at: E:\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at E:\android-studio
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

And this is the code:

clockIn(String number, String name, String company, String coords) async {
  print(uri);

  // var response = await http.post(uri, body: {
  //   'Employee_Number': number,
  //   'Employee_Name': name,
  //   'Company_Name': company,
  //   'Coords_In': coords,
  //   'Type': 'IN'
  // });

  var response = await http.get("https://google.com");

  final statusCode = response.statusCode;
  print('Response Status code: $statusCode');
}

I've tried try-catch as well, but nothing returns. There aren't any errors anywhere as well. Really confusing me. I tried it on AVD as well as my own device.

Heres where its called:

onPressed: () {
                      if (!isActivated) return;
                      getEmployeeData().then((value) async {
                        Position pos = await Geolocator().getCurrentPosition(
                            desiredAccuracy: LocationAccuracy.best);

                        clockIn(value[0], value[1], value[2],
                            "${pos.latitude}, ${pos.longitude}");
                      });
                    }
2 Answers

I think it is because of google, I tried that code with different urls and it get respond for example;

clockIn() async {
    print("uri");
    var myUrl = 'https://www.msn.com';
    var response = await http.get(myUrl);
    print('Response status: ${response.statusCode}');
    print('Response body: ${response.body}');
  }

I downgraded to the stable channel and now it seems to be working fine on my mobile device, but not on the emulator.

Related