singleSelectFormEntry method
Implementation
Widget singleSelectFormEntry({
String title = 'Select Option',
String subTitle = 'Choose one option from the list',
required List<String> options,
String? hintText,
IconData iconData = Icons.list,
Function(String?)? onChanged,
String? defaultValue,
String? Function(String?)? validator,
bool isRequired = false,
}) {
if (options.isEmpty) {
throw ArgumentError('Options list cannot be empty');
}
if (!options.contains(defaultValue)) {
defaultValue = null;
}
return formEntry(
title: title,
subTitle: subTitle,
inputWidget: DropdownButtonFormField<String>(
value: defaultValue,
dropdownColor: Colors.white,
style: const TextStyle(
color: Colors.black87,
fontSize: 16,
fontWeight: FontWeight.w400,
),
hint: Text(
hintText ?? 'Select an option',
style: TextStyle(
color: Colors.grey[600],
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
icon: Icon(
Icons.keyboard_arrow_down,
color: Colors.grey[600],
size: 24,
),
decoration: elegantInputDecoration(
hintText: '',
prefix: Icon(iconData, color: Colors.grey[600]),
),
menuMaxHeight: 300,
items: options.map((String option) {
return DropdownMenuItem<String>(
value: option,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 4.0,
),
child: Text(
option,
style: const TextStyle(
color: Colors.black87,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
),
);
}).toList(),
onChanged: isEdit
? (value) {
onChanged?.call(value);
widget.formKey.currentState?.save();
widget.onModified?.call();
}
: null,
validator:
validator ??
(isRequired
? (value) => value == null || value.isEmpty
? '$title is required'
: null
: null),
),
);
}