json - 错误: The argument type 'int' can't be assigned to the parameter type 'String'

标签 json flutter dart error-handling flutter-layout

我想在此代码中使用索引,但在代码中给我错误

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/

相关文章:

java - 如何在 Java 中解析 JSON 对象,就地更新它,然后将其保存回磁盘?

flutter - 为什么静态字段无法通过实例访问

flutter - 在Flutter中使用dio上传多部分图像文件的问题

flutter - Flutter文本字段onChanged-检测最后键入的文本是否是标记句柄 '@mention'

php - 在 Swift 中检索和使用整个 MYSQL 表

java - 在 Android 中使用日出/日落 REST API。如何正确传递获取到的位置坐标的URL?

Java - XML 到 JSON 转换(org.json.JSONException : Mismatched meta and head at character 573 )

firebase - 如何将列表作为参数发送到Flutter中的Firebase函数?

sqlite - Flutter 创建 sqlite 数据库助手以仅返回 1 个字符串或任何其他单个对象类型

dart - 自动重新启动导致 DART 语言服务器应用程序崩溃