flutter

Send HTTP Get request in Flutter or Dart

In this post, we are listing some code examples that can be helpful in sending HTTP Get requests in Flutter or Dart. We use the http package of Dart to send requests.

import 'dart:convert';
import 'package:http/http.dart' as http;

void main {
    final response = await http.get(Uri.parse("https://domain.com/endpoint?data=hello"));

    String responseData = utf8.decode(response.bodyBytes);

    print(json.decode(responseData));
}

We are using package:http/http.dart package to send HTTP get request. We are also using dart:convert package to convert our JSON response using json.decode(data) function.

If you are developing for the android platform, you need to add the user permission in AndroidManifest.xml file. The location of the manifest file is:

android/app/src/main/AndroidManifest.xml

The user permission code to be added to manifest file is:

<uses-permission android:name="android.permission.INTERNET"/>
Was this helpful?