0

Relevant code:

  String _baseUrl = 'localhost:3001/api/v1';
  String _path = 'items';
  Uri uri = Uri.http(_baseUrl, _path); 

The error occurs on the call to Uri.http. Here's the error:

FormatException (FormatException: Invalid radix-10 number (at character 1)
3001/api/v1
^
Benjamin Lee
  • 1,014
  • 10
  • 24
  • Please just use [`Uri.parse`](https://stackoverflow.com/a/67540701/) instead. Why do so many people insist on using `Uri.http`/`Uri.https`? – jamesdlin May 20 '21 at 23:00

1 Answers1

0

The error is misleading. The problem doesn't have to do with the 3001 portion, instead Uri.http is expecting the base_url to be more, well, basic.

Changing the code to this resolved the problem:

  String _baseUrl = 'localhost:3001';
  String _path = 'api/v1/items';
  Uri uri = Uri.http(_baseUrl, _path);

note: if using a device (android or ios), replace localhost with the specific address, see: How to point to localhost:8000 with the Dart http package in Flutter?

Benjamin Lee
  • 1,014
  • 10
  • 24