close

[Solved] The argument type ‘String’ can’t be assigned to the parameter type ‘int’

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. The argument type ‘String’ can’t be assigned to the parameter type ‘int’ in the flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How The argument type ‘String’ can’t be assigned to the parameter type ‘int’ Error Occurs ?

I am fetching data from API and I am using data from API to Text Widget in flutter. But it is showing an error about data type that’s:

Card(
              child: Container(
                child: Text(data[index]['name']), //error red underlying with 'name'
                padding: EdgeInsets.all(15),
              ),
            )

How to Solve The argument type ‘String’ can’t be assigned to the parameter type ‘int’ Error?

  1. How to Solve The argument type 'String' can't be assigned to the parameter type 'int' Error?

    to Solve The argument type 'String' can't be assigned to the parameter type 'int' Error Simple Solution is You have to set data the variable to List type. Just Like Below Example. Now you can use the data variable name parameter with your index. Same as below.Your error must be solved by this solution.

  2. The argument type 'String' can't be assigned to the parameter type 'int'

    to Solve The argument type 'String' can't be assigned to the parameter type 'int' Error Simple Solution is You have to set data the variable to List type. Just Like Below Example. Now you can use the data variable name parameter with your index. Same as below.Your error must be solved by this solution.

Solution 1

Simple Solution is You have to set data variable to List type. Just Like Below Example.

  List data = [
    {"name": "john"}
  ];

Now you can use data variable name parameter with your index. Same as below.

Card(
              child: Container(
                child: Text(data[0]['name']),
                padding: EdgeInsets.all(15),
              ),
            )

Your error must be solved by this solution.

Solution 2

The reason is that http.get can’t work with strings anymore. You need to use Uri to parse the HTTP address.

I had the same issue which I fixed it with this approach:

var url = Uri.parse("https://your_api");

then call it like this (attaching the http):

http.Response response = await http.get(url);

This should work.

Summery

So, It’s All About this error. I hope this tutorial helps you to solve your error. Please Comment Below if You stucks anywhere with my code.

Also Check Out Below Tutorials

1 thought on “[Solved] The argument type ‘String’ can’t be assigned to the parameter type ‘int’”

Leave a Comment

%d bloggers like this: