getTabModels function
contexts need to be the contexts of the array parent
e.g. for this formData entity quote.livesAssuredDetails which has array []
formData is the complete formData of this form, if following the above
example, it will look like:
{ "quote": "livesAssuredDetails": [...] }
Implementation
List<S360fTabModel> getTabModels({
required Map<String, dynamic> props,
required List<NestedContext> contexts,
required Map<String, dynamic> formData,
}) {
final tabId = props['tabId'] as String?;
final tabLabel = props['tabLabel'] as String?;
if (tabId == null || tabLabel == null) {
return [];
}
final models = <S360fTabModel>[];
final idDataKey = getTabIdKey(props);
final labelDataKey = extractFirstPlaceholderKey(tabLabel);
final formArrayData = getNestedFormValue(
formData,
FormSchemaTraversal.getFormFieldKey(contexts),
);
if (formArrayData is List && formArrayData.isNotEmpty) {
// iterate through the form array data to populate the tab models
for (final (item as Map<String, dynamic>) in formArrayData) {
final tabModel = S360fTabModel(
id: item[idDataKey] as Object? ?? '',
label: item[labelDataKey]?.toString() ?? '',
);
models.add(tabModel);
}
}
return models;
}