getDropdown<T> function

Widget getDropdown<T>({
  1. FocusNode? focusNode,
  2. String? icon,
  3. required List<T> list,
  4. String? label,
  5. required dynamic getText(
    1. T
    ),
  6. required Rx<T?> selected,
  7. void additionalOnChanged(
    1. T?
    )?,
  8. bool readOnly = false,
})

Implementation

Widget getDropdown<T>({
  FocusNode? focusNode,
  String? icon,
  required List<T> list,
  String? label,
  required Function(T) getText,
  required Rx<T?> selected,
  void Function(T?)? additionalOnChanged,
  bool readOnly = false,
}) {
  return Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      if (label != null) ...[
        getSpaceHeight(.5),
        getCustomText(label, color: MahasColors.greyColor),
      ],
      Padding(
        padding: EdgeInsets.symmetric(
            vertical: MahasDimensions.getHeightPercentSize(1.2)),
        child: SizedBox(
          height: MahasDimensions.getInputHeight(),
          child: Container(
            padding: EdgeInsets.symmetric(
                horizontal: MahasDimensions.getWidthPercentSize(2.5)),
            decoration: ShapeDecoration(
              color: Colors.transparent,
              shape: SmoothRectangleBorder(
                side: BorderSide(color: MahasColors.inputBorderColor, width: 1),
                borderRadius: SmoothBorderRadius(
                  cornerRadius: MahasDimensions.getInputRadius(),
                  cornerSmoothing: 0.8,
                ),
              ),
            ),
            child: Center(
              child: Obx(
                () => DropdownButton<T>(
                  dropdownColor: MahasColors.backgroundColor,
                  isExpanded: true,
                  itemHeight: null,
                  isDense: true,
                  underline: getSpaceHeight(0),
                  focusNode: focusNode,
                  items: list.map((T model) {
                    return DropdownMenuItem<T>(
                      value: model,
                      child: Row(
                        children: [
                          if (icon != null) ...[
                            getIcon(icon, color: MahasColors.greyColor),
                            getSpaceWidth(1),
                          ],
                          Expanded(
                            child: Text(
                              getText(model),
                              style: MahasDimensions.getDropdownItemTextStyle(),
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ],
                      ),
                    );
                  }).toList(),
                  onChanged: readOnly
                      ? null
                      : (value) {
                          if (value != null) selected.value = value;
                          if (additionalOnChanged != null) {
                            additionalOnChanged(value);
                          }
                        },
                  value: selected.value,
                ),
              ),
            ),
          ),
        ),
      ),
    ],
  );
}