![](/img/trans.png)
[英]1 positional argument(s) expected, but 0 found. Try adding the missing arguments
[英]Flutter 3 positional argument(s) expected, but 2 found. Try adding the missing arguments
我正在使用這個 model:
class ElementTask {
final String name;
final bool isDone;
ElementTask(this.name, this.isDone);
}
現在我想補充:
final int frequency;
但后來我在其他 class 中收到此錯誤:
需要 3 個位置參數,但找到了 2 個。 嘗試添加缺少的 arguments。
我正在使用這段代碼:
getExpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) {
List<ElementTask> listElement = [];
int nbIsDone = 0;
if (widget.user.uid.isNotEmpty) {
// ignore: missing_return
snapshot.data.documents.map<Column>((f) {
if (f.documentID == widget.currentList.keys.elementAt(widget.i)) {
f.data.forEach((a, b) { //<--error here**
if (b.runtimeType == bool) {
listElement.add(ElementTask(a, b));
}
});
}
}).toList();
for (var i in listElement) {
if (i.isDone) {
nbIsDone++;
}
}
我能做些什么來解決它? 我應該添加 c 還是其他?
如果您想將frequency
設為可選,請將其設為可空。 並使用命名參數。
class ElementTask {
final String name;
final bool isDone;
final int? frequency;
ElementTask(this.name, this.isDone,{this.frequency});
}
如果你喜歡它需要它,你需要通過三個項目。
更多關於構造函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.