简体   繁体   English

尽管在 flutter 中使用了 .toString(),但为什么我会收到错误“类型‘int’不是‘String’类型的子集?”

[英]Why am I getting the error "type 'int' is not a subset of type 'String' despite using .toString() in flutter?

I am currently trying to pull data from a Cloud Firestore instance.我目前正在尝试从 Cloud Firestore 实例中提取数据。 No actual data is there yet just some sample testing data.没有实际数据,只有一些样本测试数据。 The problem is I am coming across an error:问题是我遇到了一个错误:

Another Exception was thrown: type 'int' is not a subset of type 'String'

To troubleshoot this I tried to use.toString() as shown below since the faulty data is an int but I am putting it into a Text() widget but it continues to throw the exception.为了解决这个问题,我尝试使用 .toString() 如下所示,因为错误数据是一个 int,但我将它放入 Text() 小部件中,但它继续抛出异常。

The code:代码:

  Widget buildItem(BuildContext context, DocumentSnapshot document) {
    return ListTile(
      title: Row(
        children: [
          Expanded(
            child: Text(
              document['Name'],
              style: Theme.of(context).textTheme.headline1,
            ),
          ),
          Container(
            decoration: const BoxDecoration(
              color: kBlueLight,
            ),
            padding: const EdgeInsets.all(10),
            child: Text(
              document['Money'].toString(), //The exception is complaining about this line. I have tried with and without .toString()
              style: Theme.of(context).textTheme.displaySmall,
            ),
          )
        ],
      ),```

Try to replace尝试更换

document['Name']

to

document.get('Name')

and replace并更换

document['Money'].toString()

to

document.get('Money').toString()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 iOS(颤振应用程序)中收到 Firebase AppCheck 错误 - Why am I getting a Firebase AppCheck error in iOS (Flutter app) 没有为“对象”类型定义运算符“[]”。 尝试定义运算符'[]'。 为什么我在我的列表视图生成器中收到此错误? - The operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]'. Why I am getting this error in my listview builder? 在 terraform 模块中使用列表(字符串)数据类型时出错 - getting error while using list(string) data type in terraform module Flutter 返回错误类型 'List<dynamic> ' 不是类型 'String' 的子类型</dynamic> - Flutter returning error type 'List<dynamic>' is not a subtype of type 'String' 将日期数据上传到 flutter 中的 firestore 时出现错误 - I am getting error while uploading date data to firestore in flutter dart/flutter :: type 'Null' is not a subtype of type 'String' in type cast ERRor,无法获取数据 - dart/flutter:: type 'Null' is not a subtype of type 'String' in type cast ERRor, not able to fetch data “String”类型不是“index”的“int”类型的子类型 - type 'String' is not a subtype of type 'int' of 'index' Flutter:“DateTime”类型不是“String”类型的子类型 - Flutter: type 'DateTime' is not a subtype of type 'String' Flutter StreamBuilder小部件错误:类型'()=&gt; Map<string, dynamic> ' 不是类型 'DocumentSnapshot 的子类型<object?> ' 在类型转换中</object?></string,> - Flutter StreamBuilder widget Error : type ' () => Map<String, dynamic >' is not a subtype of type 'DocumentSnapshot<Object?>' in type cast 输入“未来<null> ' 不是 flutter 和 Firebase 中类型转换中类型 'String' 的子类型</null> - type 'Future<Null>' is not a subtype of type 'String' in type cast in flutter and Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM