[英]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.