toTitleSegments method
Implementation
List<String> toTitleSegments(DJson data) {
final List<String> titleSegments = [];
for (int i = 0; i < length; i++) {
final TitleField titleField = this[i];
final bool isLast = i == length - 1;
final bool isFirst = i == 0;
TitleField? prevField = isFirst ? null : this[i - 1];
TitleField? nextField = isLast ? null : this[i + 1];
if (prevField != null && prevField.isNotValid) {
prevField = null;
}
if (nextField != null && nextField.isNotValid) {
nextField = null;
}
if (titleField.isNotValid) {
continue;
}
if (titleField is FieldsDecorator) {
titleSegments.add(titleField.strictValue);
} else if (titleField is FieldsDivider) {
if (prevField != null && prevField is ExternalField && nextField != null && nextField is ExternalField) {
titleSegments.add(titleField.strictValue);
}
} else if (titleField is ExternalField) {
final Object? value = data[titleField.strictValue];
if (prevField != null && prevField is ExternalField) {
/// ? Default divider if there are no one [FieldsDivider] between [ExternalField]s
titleSegments.add(' ');
}
if (value == null) {
titleSegments.add('null');
} else if (value is String || value is num || value is bool) {
titleSegments.add(value.toString());
} else {
titleSegments.add('Object(${value.runtimeType})');
}
}
}
return titleSegments;
}