我想在此代码中使用索引,但在代码中给我错误
Error: The argument type 'int' can't be assigned to the parameter type 'String'.
user.index,
^
码final index = Padding(
padding: EdgeInsets.all(8.0),
child: Text(
user.index,
style: TextStyle(fontSize: 14.0, color: Colors.black),
),
);
声明如下class User {
final int index;
final String about;
final String name;
final String email;
final String picture;
User(this.index, this.about, this.name, this.email, this.picture);
}
最佳答案
您不能将整数发送到String类型的参数,因此基本上,您只需要使用toString方法将整数转换为字符串。
如有任何疑问,请查看here上的文档。
final index = Padding(
padding: EdgeInsets.all(8.0),
child: Text('${user.index}'),
style: TextStyle(fontSize: 14.0, color: Colors.black),
),
);
关于json - 错误: The argument type 'int' can't be assigned to the parameter type 'String' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60602854/