必须初始化不可为空的实例字段'name'



获取构造函数名称为"的不可为null实例的错误;面包;面包课。我试着从其他Dart类中纠正我的语法,比如我的Bakery类。Bakery类Constructor Name中没有错误。我不明白我在哪里犯了错误。

import 'bread.dart';
class Bakery{
Bakery(
this.name,
this.waitTime,
this.distance,
this.label,
this.logoUrl,
this.desc,
this.score,
this.menu,
);
String name;
String waitTime;
String distance;
String label;
String logoUrl;
String desc;
num score;
Map<String, List<Bread>> menu;
}
class Bread{
Bread(
this.imgUrl,
this.desc,
this.waitTime,
this.score,
this.cal,
this.price,
this.quantity,
this.ingredients,
this.about,
{this.highlight=false}
);
String imgUrl;
String desc;
String name;
String waitTime;
num score;
String cal;
num price;
num quantity;
List<Map<String, String>> ingredients;
String about;
bool highlight;
}

构造函数中缺少this.name。(见第3行(

class Bread {
Bread(
this.name,
this.imgUrl,
this.desc,
this.waitTime,
this.score,
this.cal,
this.price,
this.quantity,
this.ingredients,
this.about, {
this.highlight = false,
});
String imgUrl;
String desc;
String name;
String waitTime;
num score;
String cal;
num price;
num quantity;
List<Map<String, String>> ingredients;
String about;
bool highlight;
}

最新更新