sách gpt4 ăn đã đi

dart - 如何修复类型 '_InternalLinkedHashMap' 不是类型转换中类型 'List' 的子类型

In lại 作者:IT王子 更新时间:2023-10-29 06:43:20 30 4
mua khóa gpt4 giày nike

我创建了一个方法,当我构建它时,出现了这个错误:

type '_InternalLinkedHashMap' is not a subtype of type 'List' in type cast

然后我删除了方法,错误仍然存在。

Đây là mã của tôi:

class Produkt{
Tên chuỗi;
int anzahl;

Produkt({
this.name,
this.anzahl,
});

factory Produkt.fromJson(Map parsedJson){
return Produkt(
name:parsedJson['Name'],
anzahl:parsedJson['Anzahl']
);
}

Map toProduktJson() =>
{
"Name" : name,
"Anzahl" : anzahl
};
}

类产品列表

class ProduktList{
final List produkte;

ProduktList({
this.produkte,
});

factory ProduktList.fromJson(Map parsedJson){
var list = parsedJson["Produkte"] as List;
List produkte = list.map((i) => Produkt.fromJson(i.cast())).toList();

return ProduktList(
produkte: produkte,
);
}

Map toProdukteJson() =>
{
"Produkte" : [
produkte[0].toProduktJson(),
produkte[1].toProduktJson(),
]
};
}

我认为错误来自这里,但我不确定:

datenUebertragen(int index, AsyncSnapshot snapshot, ProduktList produkte){

Firestore.instance.runTransaction((transaction) async{
await transaction.update(
Firestore.instance.collection("Benutzer").document("Anton").collection("Einkaufsliste").document(
snapshot.data.documents[index].documentID),
produkte.toProdukteJson()
);
}
);
}

我在 IconButton onPressed 上调用此方法。谁能帮帮我?

Cảm ơn

biên tập:

我这样调用它:

ProduktList produkte = new ProduktList.fromJson(snapshot.data.documents[index].data);

数据看起来像:

{Produkte: [{Anzahl: 201, Name: Zucker}, {Anzahl: 10, Name: Backpulver}]}

biên tập:

nhập mô tả hình ảnh ở đây

看起来像这样!

biên tập:

nhập mô tả hình ảnh ở đây

câu trả lời hay nhất

尝试改变这个:

 var list = parsedJson["Produkte"] as List;

để kết thúc này:

 final List list = parsedJson["Produkte"] as List;

关于dart - 如何修复类型 '_InternalLinkedHashMap' 不是类型转换中类型 'List' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54171833/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress