Skip to content

Dart compile error

Flutter: “The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’”

A call like http.get('https://api.example.com/items') fails to compile with The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’. Since version 0.13.0, package:http accepts only a Uri for the URL, so code and tutorials written for older versions break after an upgrade.

Rather hand it over? App Fix Ticket: One reproducible bug in an existing mobile or web app, diagnosed and fixed.The Fix is $1,200 in total. The $450 Diagnosis is optional and credited toward it.

Full refund if Simon can’t take it on once he sees your project, or if you cancel before work starts. Refund terms.

Short answer

Wrap the string in Uri.parse: http.get(Uri.parse(url)). For URLs you build from parts, use Uri.https(host, path, queryParameters), which also encodes query values for you.

Rather not fix it yourself? App Fix Ticket fixes one reproducible bug at a fixed price, with an optional Diagnosis that is credited toward the fix.

Why a String is rejected, and the fix

  1. 01

    Code written for package:http before 0.13

    “All APIs which previously allowed a String or Uri to be passed now require a Uri.” pub.dev, package:http 0.13.0 changelog

    get, post, put, delete and the Client methods all take a Uri now. Convert the string once, at the call.

    import 'package:http/http.dart' as http;
    
    final response = await http.get(Uri.parse('https://api.example.com/items'));
  2. 02

    A URL built by joining strings

    String concatenation breaks on spaces and special characters in query values. Uri.https builds the URL from parts and encodes the query for you; use Uri.http for plain http, such as a local server. Pass the bare host (api.example.com), not https://api.example.com.

    final uri = Uri.https('api.example.com', '/search', {
      'q': query,
      'page': '$page',
    });
    final response = await http.get(uri);
  3. 03

    url_launcher and WebView calls

    The same error comes from launchUrl and canLaunchUrl in url_launcher (the old launch took a String) and from WebViewController.loadRequest. Parse the string first.

    await launchUrl(Uri.parse(url));
    controller.loadRequest(Uri.parse(url));
  4. 04

    A malformed URL string

    Uri.parse throws a FormatException for a string that isn’t a valid URI. Use Uri.tryParse for user input, which returns null instead of throwing.

    final uri = Uri.tryParse(input);
    if (uri == null || !uri.hasScheme) {
      // show a validation error
    }

Checked against the vendor’s docs on : pub.dev: package:http changelog (0.13.0); Dart API: Uri.parse.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
A buyer in the United States, July 2022. Shopify on Fiverr
Read 126 of the 127 Fiverr reviews

Related: Flutter “Connection closed before full header” · Flutter “SocketException: Failed host lookup” · Flutter “The parameter can’t have a value of null” · Flutter “can’t be assigned to the parameter type ‘PreferredSizeWidget’”

Questions

More on this error

Should I pin http to an old version instead?

No. Versions before 0.13 aren’t null safe, so current Dart rejects them. Changing each call to Uri.parse is a quick, mechanical fix.

Does Dio have the same rule?

No, Dio accepts a String path. This error comes from package:http, url_launcher, WebView and other APIs whose parameter type is Uri.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it. If you already know the cause, you can pay for the fix directly; if not, start with a written diagnosis, which is credited toward the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Ask Simon for a price range

Send the error and what you were doing. Simon replies by email, usually within one business day, with a price range.