Model constructor
Model({})
Implementation
Model({
required this.name,
required this.icon,
required this.fields,
this.isCollection = true,
this.sort = 0,
this.showInMenu = true,
String? id,
this.codeFirstEntity = true,
this.isHybrid = false,
}) : id = id ?? toSnakeCase(name) {
/// ? FLATTEN FIELDS
flattenFields = fields.fold(<Field>[], (List<Field> allFields, List<Field> currentRowFields) {
for (final Field field in currentRowFields) {
allFields.add(field);
if (field.virtualFields.isNotEmpty) {
allFields.addAll(field.virtualFields);
}
}
return allFields;
});
/// ? LIST FIELDS
final List<Field> listFieldsTemp = flattenFields.where((Field field) => field.showInList).toList();
listFieldsTemp.sort((first, second) => first.sort.compareTo(second.sort));
listFields = listFieldsTemp;
/// ? ID FIELD
final List<IdField> idFieldsTemp = flattenFields.whereType<IdField>().toList();
assert(idFieldsTemp.isNotEmpty, 'You should specify at least a one $IdField at your model $runtimeType');
idField = idFieldsTemp.first;
/// ? DYNAMIC FIELDS IDS
final List<String> dynamicFieldsTemp = [];
for (final Field field in flattenFields) {
if (field is DynamicField && field is! StructuredField && field is! StructureField) {
dynamicFieldsTemp.add(field.id);
}
}
dynamicFields = dynamicFieldsTemp;
}