Flutter Solve The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’ Error

Hello friends, recently when I was reading an old article on my website, Then I found that flutter has changed some of its coding pattern. I was working on a flutter application project where I need to parse JSON data from server with HTTP Dark Pub package. But when I ran my old code then It starts showing me couple of errors which I haven’t seen before. So I thought let’s make a complete tutorial on those errors to solve them. It might be helpful for some new flutter developers. So in this tutorial we would learn about Flutter Solve The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’ Error in HTTP Dart Pub package.

Contents in this project Flutter Solve The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’ Error :-

1. First of all below is the screenshot of my Visual Studio code editor where it is showing us the error.

Flutter Solve The argument type 'String' can't be assigned to the parameter type 'Uri' Error

2. Now for a more brief explanation, What I am doing here is parsing the JSON from URL. So in the await http.get(uri) method the uri is the String variable which holds my server URL. So to solve this error all we have to do is Wrap the uri or the URL into Uri.parse() method. See the code example below.

This would surely resolve the error. Happy coding friends 🙂 .

Leave a Reply

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