Bizarre Dart compiler warnings on http lib


I’m trying to use Dart’s http library for making simple HTTP GET and POST requests:

import 'package:http/http.dart' as http;
import 'package:http/src/response.dart';

void main() {
    String json = getSomeJSONString();, body: json, encoding: Encoding.getByName("UTF-8")).then(onResponse);

void onResponse(Response response) {
    // Do something

When I run this through pub build I get:

[Dart2JS on myapp-client|web/myapp_client.dart]:Building myapp-client......

[Dart2JS on myapp-client|web/myapp_client.dart]:
../../../../../sandbox/workbench/dart/dart/dart-sdk/lib/core/uri.dart:1133:17: Info: This is the method declaration.packages/http/src/utils.dart:41:42: Warning: Arguments do not match the expected parameters of 'encodeQueryComponent'.
static String encodeQueryComponent(String component) {

[Dart2JS on myapp-client|web/myapp_client.dart]:pairs.add([Uri.encodeQueryComponent(key, encoding: encoding),

../../../../../sandbox/workbench/dart/dart/dart-sdk/lib/core/uri.dart:1133:17: Info: This is the method declaration.
static String encodeQueryComponent(String component) {

[Dart2JS on myapp-client|web/myapp_client.dart]:
packages/http/src/utils.dart:42:42: Warning: Arguments do not match the expected parameters of 'encodeQueryComponent'.
 Uri.encodeQueryComponent(value, encoding: encoding)]));
[Dart2JS on myapp-client|web/myapp_client.dart]:
packages/http/src/utils.dart:41:58: Warning: No named argument 'encoding' found on method.
pairs.add([Uri.encodeQueryComponent(key, encoding: encoding),
[Dart2JS on myapp-client|web/myapp_client.dart]:
packages/http/src/utils.dart:42:60: Warning: No named argument 'encoding' found on method.
 Uri.encodeQueryComponent(value, encoding: encoding)]));
[Info in Dart2JS]:
Generated myapp-client|web/myapp_client.dart.js (246641 characters) in 0:00:09.640230
Built 14 files!

So a few questions:

  1. What are these warnings, and why am I getting them?
  2. What do I need to do to get them to go away (fix them)?
  3. Why do I need to include this http library as a dependency if it is a part of the Dart language/core?


The http package depends on dart:io, which is not available to Web client applications, so you will not be able to use it (this is not the source of your warnings, but there is not much point debugging them when you can’t use the package anyway).

Use something like adaj instead.

As far as I understand the http package is not part of the Dart core libraries, though it is worked on by the Dart team. I am not entirely sure what the decision is for making a library part of Dart core or not (dart: prefix). In this case I assume it is because dart:io already has http support.

Answered By – Pixel Elephant

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *