簡體   English   中英

錯誤:預期 3 個位置參數,但找到 0 個

[英]error: 3 positional argument(s) expected, but 0 found

我已經聲明了我的 arguments 但它對我說 3 pos。 arguments 預期但發現 0。 錯誤在Article.fromJSON部分。 有人知道為什么嗎?

class Article {
  final String id;
  final String caption;
  final DateTime timestamp;

  Article(this.id, this.caption, this.timestamp, );


  factory Article.fromJSON(Map<String, dynamic> jsonMap) {
    return Article(
      id: jsonMap['id'] as String,
      caption: jsonMap['caption'] as String ,
      timestamp: jsonMap['timestamp'] as DateTime ,
      
    );
  }

  Map toMap() {
    var map = new Map<String, dynamic>();
    map["id"] = id;
    map["caption"] = caption ;
    map["timestamp"] = timestamp ;
    return map;
  }
  
}

這是因為你的參數沒有命名,

改變

文章(this.id,this.caption,this.timestamp,);

文章({this.id, this.caption, this.timestamp, });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM