我有这样的模型(简化):
@immutable
class CountryModel {
final String name;
final String isoCode;
final String assetPath;
const CountryModel({
required this.name,
required this.isoCode,
}) : assetPath = 'assets/countries/$isoCode.PNG';
}
现在我决定迁移到freezed
但不明白如何处理像assetPath
我有很多模型,它们的初始值基于构造函数参数
我的冷冻模型:
part 'country_model.freezed.dart';
@freezed
class CountryModel with _$CountryModel {
const factory CountryModel({
required String name,
required String isoCode,
}) = _CountryModel;
}
// : assetPath = 'assets/countries/$isoCode.PNG'
如何在此处添加assetPath 字段?
所以在迁移到冻结之前,如果我CountryModel
这样创建
CountryModel(name: 'name', isoCode: 'XX');
assetPath
值应该是'assets/countries/XX.PNG'