Untitled
user_7176186
plain_text
3 years ago
3.8 kB
8
Indexable
part of 'components.dart';
class TextFormDropdown extends StatefulWidget {
final String? hintText;
final Widget? icon;
final Function(String?)? onChanged;
final String? defaultSelectedValue;
const TextFormDropdown(
{Key? key,
this.icon,
this.hintText,
this.onChanged,
this.defaultSelectedValue})
: super(key: key);
@override
State<TextFormDropdown> createState() => _TextFormDropdownState();
}
class _TextFormDropdownState extends State<TextFormDropdown> {
String? selectedValue;
@override
void initState() {
super.initState();
selectedValue = widget.defaultSelectedValue ?? "Female";
}
@override
Widget build(BuildContext context) {
List<String> itemStringList = [
"-- Pilih Higlight --",
"Female",
"Male",
"other"
];
return Padding(
padding: const EdgeInsets.only(top: 10),
child: FormField<String>(
initialValue: itemStringList[0],
enabled: true,
builder: (FormFieldState<String> field) {
return InputDecorator(
decoration: InputDecoration(
errorText: field.errorText,
hintText: widget.hintText,
contentPadding: const EdgeInsets.only(
top: 10,
left: 19,
right: 19,
bottom: 10,
),
isDense: true,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: const BorderSide(color: Palette.lightBlue),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: const BorderSide(
color: Palette.lightBlue,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: const BorderSide(
color: Palette.lightBlue,
width: 1.0,
),
),
),
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
isExpanded: false,
value: selectedValue,
icon: widget.icon,
iconSize: 24,
elevation: 16,
style: TextStyle(
fontSize: Theme.of(context).textTheme.bodyMedium!.fontSize!,
fontFamily:
Theme.of(context).textTheme.bodyMedium!.fontFamily,
color: Theme.of(context).textTheme.bodyMedium!.color,
),
underline: Container(
height: 0,
color: Colors.grey[300],
),
onChanged: (String? newValue) {
setState(() {
selectedValue = newValue!;
});
if (widget.onChanged != null) {
widget.onChanged!(selectedValue);
}
},
items: itemStringList.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 0.0,
vertical: 0.0,
),
child: Text(value),
),
);
}).toList(),
),
),
),
);
},
),
);
}
}
Editor is loading...