StringDropdownField<T extends DropdownModel> constructor
StringDropdownField<T extends DropdownModel> ({
- Key? key,
- List<
T> ? data, - bool isActive = true,
- TextStyle? errorStyle,
- Color? colorText,
- Color? colorBackground,
- String? textHint,
- FormFieldSetter<
T> ? onSaved, - FormFieldValidator<
T> ? validator, - T? initialValue,
- dynamic onSelected(
- T
Implementation
StringDropdownField(
{Key? key,
this.data,
this.isActive = true,
this.errorStyle,
this.colorText,
this.colorBackground,
this.textHint,
FormFieldSetter<T>? onSaved,
FormFieldValidator<T>? validator,
T? initialValue,
Function(T)? onSelected})
: super(
key: key,
onSaved: onSaved,
validator: validator,
initialValue: initialValue,
autovalidateMode: AutovalidateMode.onUserInteraction,
builder: (FormFieldState<T> state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
MyDropdown<T>(
initialValue: initialValue,
colorText: colorText ?? Colors.black,
colorBackground: colorBackground ?? Color(0xffF6F7FB),
onSelected: (item) {
if (isActive) {
onSelected!(item);
state.didChange(item);
}
},
itemBuilder: (BuildContext context) {
return List<PopupMenuEntry<T>>.generate(
(data!.length * 2 - 1), (int index) {
if (index.isEven) {
final item = data[index ~/ 2];
return PopUpObject<T>(value: item);
} else {
return MyDropdownDivider();
}
});
},
child: state.value == null
? Text(
textHint ?? 'Pilih',
)
: DropdownObject(state.value),
),
if (state.hasError)
Container(
padding: EdgeInsets.fromLTRB(4, 12, 4, 0),
child: Text(
state.errorText!,
style: errorStyle ?? TextStyle(color: Colors.red),
textAlign: TextAlign.start,
),
)
],
);
});