![](/img/trans.png)
[英]Unhandled Exception: type 'int' is not a subtype of type 'String' in flutter
[英]Flutter : Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
我正在研究顫振/火力基地項目。 這段代碼存在一些問題:
db = FirebaseDatabase.instance.reference().child("Volunteers/"+vname);
db.once().then((DataSnapshot snapshot){
Map<dynamic, dynamic> values = snapshot.value;
values.forEach((key,values) {
print(values["cont"]);
});
});
運行時,我收到此錯誤Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
請幫忙
我認為 foreach 中的值不是 object,它看起來像一個數組,所以這個 { print(values["cont"]);} 中的錯誤...如果不是那個錯誤,請打印兩個“值”並查看它們是什么。
另一個提示,有時在控制台中,當你得到錯誤時,也會得到存在錯誤的行,尤其是在 vscode 中。
這里。 value
是鍵的值。 您認為的values['const']
實際上只是value
。
values.forEach((key,value) {
print(value);
});
注意: values
已重命名為簡潔起見的value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.