prajyot sharma
prajyot sharma

Reputation: 43

Unhandled Exception: type 'String' is not a subtype of type 'Uri'

I have been working on a flutter mobile project of a taxi clone app. I have used Google Maps API for GeoCoding and Directions. I have been following a tutorial on youtube (the link). When I run the project I don't get any data and see this error in the console

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type 'String' is not a subtype of type 'Uri'

Please help me. I am doing it for a school project

Upvotes: 4

Views: 19052

Answers (2)

Nelson Jr.
Nelson Jr.

Reputation: 1207

It's most likely due to the versioning of the http package. Looking at the video tutorial, it appears that the teacher used http 0.12.2, while it seems that you are using a later version(0.13.0 or above). If you look at the changelog, you'd see this note on the changes made after 0.12.2:

Breaking All APIs which previously allowed a String or Uri to be passed now require a Uri.

To solve your issue, you need to pass a Uri instead of a String

var url = Uri.parse('https://example.com'); 

Upvotes: 20

BLKKKBVSIK
BLKKKBVSIK

Reputation: 3566

You probably used a String ("https://yoursuperendpoint.com" for exemple)
And you need to use a URI: there is a special Uri class for this.

You have the documentation there: https://api.flutter.dev/flutter/dart-core/Uri-class.html

But you probably will use the Uri.tryParse() method.

Upvotes: 1

Related Questions