【发布时间】:2022-01-03 11:33:43
【问题描述】:
我收到如下错误:
不能从工厂构造函数访问实例成员。 尝试删除对实例成员的引用。
有什么解决办法吗?
class DepartureModel {
String route;
String departureTime;
String arrivalTime;
String tourType;
List<String> daysOfWeek;
DepartureModel({
required this.route,
required this.departureTime,
required this.arrivalTime,
required this.tourType,
required this.daysOfWeek,
});
//method that assign values to respective datatype vairables
factory DepartureModel.fromJson(Map<String, dynamic> json) {
return DepartureModel(
route: json['route'],
departureTime: json['departureTime'],
arrivalTime: json['arrivalTime'],
tourType: json['tourType'],
daysOfWeek: json["daysOfWeek"].forEach(
(day) {
daysOfWeek.add(day);
},
),
);
}
【问题讨论】: