mahasInputSelectWidget<T> function
Widget
mahasInputSelectWidget<T>({
- MahasInputModel? controller,
- bool showLabel = true,
- String? icon,
- String? label,
- required dynamic getText(
- T
- void additionalOnChanged(
- T?
- bool readOnly = false,
- List<
MahasMessageModel> ? validation, - int? index,
Implementation
Widget mahasInputSelectWidget<T>({
MahasInputModel? controller,
bool showLabel = true,
String? icon,
String? label,
required Function(T) getText,
void Function(T?)? additionalOnChanged,
bool readOnly = false,
List<MahasMessageModel>? validation,
int? index,
}) {
final MahasInputSelectModel<T>? con =
controller is MahasInputSelectModel<T> ? controller : null;
if (con == null) return const SizedBox.shrink();
label = showLabel ? label ?? con.label : null;
final String key = '${con.id}${index != null ? '_$index' : ''}';
final bool isValid = validation
?.firstWhereOrNull((element) => element.inputName == key)
?.errorMessages
.isEmpty ??
true;
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: MahasDimensions.getTextFieldDecoration(
colorSet: isValid
? MahasColors.inputBorderColor
: MahasColors.dangerColor.withOpacity(.4),
),
child: Center(
child: Obx(
() => DropdownButton<T>(
dropdownColor: MahasColors.backgroundColor,
isExpanded: true,
itemHeight: null,
isDense: true,
underline: getSpaceHeight(0),
focusNode: con.focusNode,
items: con.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
: (T? value) {
if (value != null) {
con.selected.value = value;
additionalOnChanged?.call(value);
}
},
value: con.selected.value,
),
),
),
),
),
),
],
);
}