getControl method
Implementation
Widget getControl(
UISchemaElement uiSchema,
JsonSchema4 schema,
BuildContext context,
) {
List<String> parts = uiSchema.scope!.split("/");
parts.removeAt(0);
String label = uiSchema.label ?? camelCaseToWords(parts.last);
if (schema.required != null && schema.required!.contains(parts.last)) {
label += "*";
}
JsonSchema4 item = getItem(parts, schema);
if (item.type == PropertyType.string.name) {
bool? multi = uiSchema.options?["multi"];
if (item.format == PropertyFormat.date.name) {
return DateControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
);
}
if (item.format == PropertyFormat.email.name) {
return EmailControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
multi: multi,
);
}
if (item.format == PropertyFormat.uri.name) {
return UriControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
multi: multi,
);
}
if (item.enumValues != null) {
return DropdownControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
enumValues: item.enumValues as List<String>,
);
}
return TextControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
minLength: item.minLength,
multi: multi,
);
} else if (item.type == PropertyType.boolean.name) {
return CheckboxControl(
label: label,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
);
} else if (item.type == PropertyType.integer.name) {
return IntegerControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
);
} else if (item.type == PropertyType.number.name) {
return NumberControl(
label: label,
description: item.description,
path: getParts(uiSchema.scope!),
jsonData: data,
callback: (Map<String, dynamic> data) {
callback(data);
},
);
}
return Container();
}