【发布时间】:2020-09-06 07:10:29
【问题描述】:
我创建了一个类JobBloc,其中包含许多属性,其中一个是另一个类对象JobModel,我想为这些属性中的每一个分配一个默认值,它工作正常,除了JobModel 属性:
class JobBloc with JobModelFormValidator {
final JobModel jobModel;
final bool isValid;
final bool showErrorMessage;
final String name;
final double ratePerHour;
final bool enableForm;
final bool showIcon;
JobBloc({
// The default value of an optional parameter must be constant.
this.jobModel = JobModel(name: 'EMPTY', ratePerHour: 0.01), // <= the error stems from this line
this.isValid = false,
this.showErrorMessage = false,
this.name = 'EMPTY',
this.enableForm = true,
this.ratePerHour = 0.01,
this.showIcon = false,
});
}
如何为我的jobModel 属性分配默认值?
【问题讨论】:
标签: class flutter dart default-value