错误:预期有3个位置参数,但发现0

时间:2020-06-27 10:33:10

标签: flutter

我已经宣布了自己的论点,但对我来说说3 pos。预期参数,但找到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;
  }
  
}

1 个答案:

答案 0 :(得分:0)

这是因为您的参数未命名

更改

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

收件人

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