render method

  1. @override
Widget render(
  1. DropdownButton element,
  2. BuildContext context,
  3. FormElementEventDispatcherFunction dispatcher,
  4. FormElementRendererFunction<FormElement> renderer,
)

Implementation

@override
Widget render(
    model.DropdownButton element,
    BuildContext context,
    FormElementEventDispatcherFunction dispatcher,
    FormElementRendererFunction renderer) {
  return LazyStreamBuilder(
    streamFactory: () => MergeStream([
      ...element.choices.map((o) => o.isVisibleChanged),
      element.propertyChanged,
    ]),
    builder: (context, _) {
      return Center(
        child: DropdownButton<String>(
          value: element.value,
          onChanged: (String? newValue) => dispatcher(
            ChangeValueEvent(
                value: newValue,
                elementId: element.id!,
                propertyName: model.SingleSelectGroup.valuePropertyName),
          ),
          items: element.choices
              .where((d) => d.isVisible)
              .whereType<model.DropdownOption>()
              .map<DropdownMenuItem<String>>(
            (model.DropdownOption option) {
              return DropdownMenuItem<String>(
                value: option.value,
                child: Text(option.label),
              );
            },
          ).toList(),
        ),
      );
    },
  );
}