Flutter 颤振型';字符串';不是类型为';int';属于';指数';从列表中获取时
尝试编译程序时,出现以下错误:Flutter 颤振型';字符串';不是类型为';int';属于';指数';从列表中获取时,flutter,dart,Flutter,Dart,尝试编译程序时,出现以下错误: ======== Exception caught by widgets library ======================================================= The following _TypeError was thrown building: type 'String' is not a subtype of type 'int' of 'index' When the exception was thrown,
======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building:
type 'String' is not a subtype of type 'int' of 'index'
When the exception was thrown, this was the stack:
#0 _HistoryPageState.builder.<anonymous closure>.<anonymous closure> (package:arkadas_testi/history.dart:54:38)
#1 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:455:22)
#2 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1213:28)
#3 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1226:55)
#4 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2535:19)
...
====================================================================================================
这就是列表的样子:[{arkadaşsim:emir,kullaniciİsim:emir,sonuc:76,yazi:Kesinlikle arkadaşOl}]
<代码>项[“sonuc”]是一个字符串
即使在将“sonuc”转换为int之后,问题仍然存在
在看了一些答案类似的问题后,我仍然找不到解决办法。我如何解决这个问题?如果当前信息不足,我可以提供更多代码。我认为这里的问题是您将puan传递给某个文本字段,而puan现在是int。 无论如何,这是我的猜测,因为你没有很好地解释这个问题
您能为我们添加更多的代码以获得一个最小的可复制示例吗?请尝试删除
int.parse()
部分代码。在映射中,如果一个值是纯整数,那么它应该作为一个返回。
void main() {
List list = [{'arkadaşİsim': 'emir', 'kullaniciİsim': 'emir', 'sonuc': 76, 'yazi': 'Kesinlikle Arkadaş Ol'}];
double sum = 0;
String string = 'String Sonuc:';
sum = list[0]['sonuc'] + 10;
//string += list[0]['sonuc']; => error, list[0]['sonuc'] => int
string = string + list[0]['sonuc'].toString();
print(sum);
print(string);
}