Home > OS >  Why isn't my DropdownButtonFormField showing the items?
Why isn't my DropdownButtonFormField showing the items?

Time:10-23

I have this Dropdown:

DropdownButtonFormField(
  value: shipmentSelected,
  hint: Text(
    'choose one',
  ),
  onChanged: (value){
    shipmentSelected = value;
  }
  items: product.shipment.map((Shipment shipment) {
    return DropdownMenuItem(
      value: shipment.code,
      child: Text(
        shipment.code,
      ),
    );
  }).toList(),
)

But it doesn't show any item... just show the hintText. How to fix it?

CodePudding user response:

You need to pass a callback function to onChanged in the DropdownButtonFormField constructor. Update shipmentSelected and rebuild from this function like so:

onChanged: (value) {
  setState(() {
    shipmentSelected = value;
  });
},
  • Related