alghwalbi_core_app
alghwalbi_core_app package is primarily intended for personal use, but feel free to use it in your projects.
Installation
To use alghwalbi_core in your Flutter project, add it to your pubspec.yaml file:
dependencies:
alghwalbi_core_app: <Latest-version>
Form Builder: Dynamic Dropdown
Dropdown fields arriving with data.queryKey: "dynamic" and a data.entityConfig are parsed as DynamicDropdownFormFieldModel (FormFieldType.dynamicDropdown). Their options are fetched from the backend entity endpoint (GET /api/v1/form-entities/{entityKey}/data) instead of being embedded in the form definition.
The package does not perform the HTTP call itself. The host app supplies a DynamicDropdownOptionsFetcher to FormFieldWidget, so authentication and base URL stay under the app's control:
FormFieldWidget(
// ... existing parameters ...
dynamicDropdownOptionsFetcher: (request) async {
final response = await apiClient.get(
'/api/v1/form-entities/${request.entityKey}/data',
queryParameters: request.toQueryParameters(),
);
return DynamicDropdownOptionsPageModel.fromJson(response.data);
},
// Required for dependent dropdowns: return the current value of the
// parent field (the stored selection map or its id).
dynamicDropdownParentValueResolver: (parentFieldKey) =>
formValues[parentFieldKey],
// Optional localizable texts.
dynamicDropdownSearchHintText: 'Search',
dynamicDropdownRetryButtonText: 'Retry',
dynamicDropdownNoResultsText: 'No results',
dynamicDropdownLoadFailedText: 'Failed to load options',
)
Behavior:
- Options load when the field is opened, with server-side search (debounced) and infinite-scroll pagination driven by the endpoint's
hasMoreflag. - The selected value stored on the model (and emitted via
onChanged) is{ "id": ..., "displayValue": ..., "entityKey": ... }, the shape the submissions endpoint expects. - A dropdown whose
entityConfig.dependsOnis set stays disabled until its parent dropdown has a value, and its selection is cleared whenever the parent value changes. The parent's id is sent asparentValuetogether withparentEntityKey. - If the fetcher throws or returns
null, the field shows a retry state. IfdynamicDropdownOptionsFetcheris not provided, dynamic dropdown fields are skipped with a warning log.