Skip to content

Dart compile errorFlutter: “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.

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.

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.

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: a written diagnosis first, then 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?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.