import 'package:car_customer_app/extensions/string_extensions.dart'; import 'package:car_customer_app/theme/colors.dart'; import 'package:car_customer_app/utils/utils.dart'; import 'package:flutter/material.dart'; class DropValue { int id; String value; String subValue; DropValue(this.id, this.value,this.subValue); } class DropdownField extends StatefulWidget { String? hint; List? list; Function(DropValue) onSelect; DropdownField(this.onSelect, {this.hint, this.list}); @override State createState() => _DropdownFieldState(); } class _DropdownFieldState extends State { DropValue? dropdownValue; List defaultV = [ new DropValue(1, "One",""), new DropValue(2, "Two",""), ]; @override Widget build(BuildContext context) { return Container( decoration: containerColorRadiusBorderWidth( Colors.transparent, 4, borderColor, 0.5, ), margin: EdgeInsets.all(2), padding: EdgeInsets.only(left: 8, right: 8), child: DropdownButton( value: dropdownValue, icon: const Icon(Icons.keyboard_arrow_down_sharp), elevation: 16, iconSize: 16, iconEnabledColor: borderColor, iconDisabledColor: borderColor, isExpanded: true, style: const TextStyle(color: Colors.black), hint: (widget.hint ?? "").toText12(color: borderColor), underline: Container( height: 0, ), onChanged: (DropValue? newValue) { setState(() { dropdownValue = newValue!; widget.onSelect(newValue); }); }, items: (widget.list ?? defaultV).map>( (DropValue value) { return DropdownMenuItem( value: value, child: value.value.toText12(), ); }, ).toList(), ), ); } }