FormatException: Scheme not starting with alphabetic character - Flutter Http Request

2.8k Views Asked by At

I make a http request in my flutter app with a simple url api:

Future<http.Response> getUsers() async {
  try {
    return await http
        .get('​https://reqres.in/api/users')
        .timeout(const Duration(seconds: 10))
        .catchError((e) {
      print("=> catchError getUsers $e");
      return null;
    });
  } on SocketException catch (e) {
    print("=> catch SocketException getUsers  $e");
    return null;
  } catch (e) {
    print("=> catch getUsers  $e");
    return null;
  }
}

And the error message is:

err FormatException: Scheme not starting with alphabetic character (at character 1) ​https://reqres.in/api/users ^

enter image description here

I have switched to different channels of the flutter version and I don't know the solution, thanks!

1

There are 1 best solutions below

0
On

Try using

http.get(Uri.parse('​https://reqres.in/api/users'))