Reputation:
How to set initial value from cache to dropdown button? have submitted button, if click submits button should add to drop-down button value. Now it's working. I need to add initial value to the drop-down button. and If add initial value and when click to submit button without selecting a value in dropdown selecting value should ant to pass
Container(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<WorkSource>(
isExpanded: true,
value: _workSources,
items: workSources.map((WorkSource value) {
return DropdownMenuItem<WorkSource>(
value: value,
child: Text(
value.description,
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
onChanged: (value) => setState(() {
workSourceIndex = value.id;
_workSources = value;
}),
style: Theme.of(context).textTheme.title,
Upvotes: 0
Views: 3203
Reputation: 5361
_workSources
in your code should be the initial value. Just assign value to that in initState()
.
Upvotes: 1