dropdown method
Widget
dropdown(
{ - dynamic component,
- required double parentWidth,
})
Implementation
Widget dropdown({var component, required double parentWidth}) {
DropdownController dropdownController = DropdownController();
return Obx(() => SizedBox(
width: (component["cssClass"] != null && component["cssClass"] != "")
? SwitchCase().componentWidthSC(
component["cssClass"],
{
"layout_1by8_col": parentWidth * 0.1,
"layout_1_col": parentWidth * 0.2,
"layout_2_col": parentWidth * 0.4,
"layout_3_col": parentWidth * 0.68,
"layout_4_col": parentWidth,
},
parentWidth * 0.2)
: parentWidth * 0.2,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AltComponent().altComponentLabel(
component: component,
label: (component["displayLabel"] != null &&
component["displayLabel"] != "")
? component["displayLabel"]
: (component["security"] != null &&
component["security"]["fieldLabel"] != null &&
component["security"]["fieldLabel"] != "")
? component["security"]["fieldLabel"]
: component["name"]),
Container(
height: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(componentBorderRadius),
border: Border.all(color: Palette.componentBorderColor)),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: DropdownButton<String>(
isExpanded: true,
alignment: AlignmentDirectional.topStart,
itemHeight: 30,
iconSize: 14,
icon: const Icon(Icons.keyboard_arrow_down_outlined),
underline: const SizedBox(),
focusColor: Colors.transparent,
style: componentTxtStyle,
hint: const Text(
'Select',
),
onChanged: (String? newValue) {
dropdownController.setSelected(newValue!);
},
value: dropdownController.selected.value == ""
? component["defaultvalDropdown"]
: dropdownController.selected.value,
items: component["options"] != null
? component["options"]
.map<DropdownMenuItem<String>>(
(value) => DropdownMenuItem<String>(
value: value["label"],
child: Text(value["label"]),
))
.toList()
: [],
),
),
),
AltComponent().altComponentInstruction(component: component)
],
),
));
}